RemoveHandler Statement
Removes the association between an event and an event handler.
Syntax
RemoveHandler event, AddressOf eventhandler
Parts
Term | Definition |
---|---|
event |
The name of the event being handled. |
eventhandler |
The name of the procedure currently handling the event. |
Remarks
The AddHandler
and RemoveHandler
statements allow you to start and stop event handling for a specific event at any time during program execution.
Note
For custom events, the RemoveHandler
statement invokes the event's RemoveHandler
accessor. For more information on custom events, see Event Statement.
Example
Sub TestEvents()
Dim Obj As New Class1
' Associate an event handler with an event.
AddHandler Obj.Ev_Event, AddressOf EventHandler
' Call the method to raise the event.
Obj.CauseSomeEvent()
' Stop handling events.
RemoveHandler Obj.Ev_Event, AddressOf EventHandler
' This event will not be handled.
Obj.CauseSomeEvent()
' Associate an event handler with an event, using a lambda.
' This handler cannot be removed.
AddHandler Obj.Ev_Event, Sub ()
MsgBox("Lambda caught event.")
End Sub
' This event will be handled by the lambda above.
Obj.CauseSomeEvent()
End Sub
Sub EventHandler()
' Handle the event.
MsgBox("EventHandler caught event.")
End Sub
Public Class Class1
' Declare an event.
Public Event Ev_Event()
Sub CauseSomeEvent()
' Raise an event.
RaiseEvent Ev_Event()
End Sub
End Class
See also
Cộng tác với chúng tôi trên GitHub
Bạn có thể tìm thấy nguồn cho nội dung này trên GitHub, nơi bạn cũng có thể tạo và xem lại các vấn đề và yêu cầu kéo. Để biết thêm thông tin, hãy xem hướng dẫn dành cho người đóng góp của chúng tôi.
Phản hồi
https://aka.ms/ContentUserFeedback.
Sắp ra mắt: Trong năm 2024, chúng tôi sẽ dần gỡ bỏ Sự cố với GitHub dưới dạng cơ chế phản hồi cho nội dung và thay thế bằng hệ thống phản hồi mới. Để biết thêm thông tin, hãy xem:Gửi và xem ý kiến phản hồi dành cho