Share vb.net sender as object e as eventargs

bigbird764

New member
### vb.net người gửi dưới dạng đối tượng e như sự kiện

** Người gửi ** và ** E ** là hai từ khóa quan trọng trong xử lý sự kiện VB.NET.Người gửi đề cập đến đối tượng đã nâng cao sự kiện, trong khi E đề cập đến các đối số sự kiện.

Để sử dụng người gửi và E trong vb.net, trước tiên bạn cần tạo một trình xử lý sự kiện.Một người xử lý sự kiện là một phương pháp được gọi là khi một sự kiện được nêu ra.Để tạo một trình xử lý sự kiện, bạn sử dụng cú pháp sau:

`` `
Private Sub MyEvent_Handler (người gửi là đối tượng, E là EventArgs)
'Mã để xử lý sự kiện diễn ra ở đây
Kết thúc phụ
`` `

Trong ví dụ này, trình xử lý sự kiện được gọi là `myevent_handler`.Tham số đầu tiên, `người gửi`, là đối tượng đã nâng cao sự kiện.Tham số thứ hai, `E`, là các đối số sự kiện.

Để sử dụng người gửi và E trong trình xử lý sự kiện của bạn, bạn có thể truy cập chúng trực tiếp trong mã.Ví dụ: mã sau in tên của đối tượng đã nêu ra sự kiện:

`` `
Private Sub MyEvent_Handler (người gửi là đối tượng, E là EventArgs)
Console.WriteLine (người gửi.Name)
Kết thúc phụ
`` `

Bạn cũng có thể sử dụng người gửi và E để truy cập các thuộc tính và phương thức của đối tượng đã nâng cao sự kiện.Ví dụ: mã sau nhận được văn bản của một nút đã được nhấp:

`` `
Nút phụ riêng1_click (người gửi dưới dạng đối tượng, E là EventArgs)
Nút mờ như nút = người gửi
Console.WriteLine (nút.text)
Kết thúc phụ
`` `

Người gửi và E là hai từ khóa mạnh mẽ có thể được sử dụng để xử lý các sự kiện trong vb.net.Bằng cách hiểu cách sử dụng chúng, bạn có thể viết các trình xử lý sự kiện hiệu quả và hiệu quả hơn.

### hashtags

* #vb.net
* #Sự kiện
* #Xử lý sự kiện
* #Người gửi
* #e
=======================================
### VB.NET Sender as Object E as EventsArgs

**Sender** and **e** are two important keywords in VB.NET event handling. Sender refers to the object that raised the event, while e refers to the event arguments.

To use sender and e in VB.NET, you first need to create an event handler. An event handler is a method that is called when an event is raised. To create an event handler, you use the following syntax:

```
Private Sub MyEvent_Handler(sender As Object, e As EventArgs)
' Code to handle the event goes here
End Sub
```

In this example, the event handler is called `MyEvent_Handler`. The first parameter, `sender`, is the object that raised the event. The second parameter, `e`, is the event arguments.

To use sender and e in your event handler, you can access them directly in the code. For example, the following code prints the name of the object that raised the event:

```
Private Sub MyEvent_Handler(sender As Object, e As EventArgs)
Console.WriteLine(sender.Name)
End Sub
```

You can also use sender and e to access the properties and methods of the object that raised the event. For example, the following code gets the text of a button that was clicked:

```
Private Sub Button1_Click(sender As Object, e As EventArgs)
Dim button As Button = sender
Console.WriteLine(button.Text)
End Sub
```

Sender and e are two powerful keywords that can be used to handle events in VB.NET. By understanding how to use them, you can write more efficient and effective event handlers.

### Hashtags

* #vb.net
* #events
* #Event handling
* #Sender
* #e
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top