RemoveHandler 陳述式
移除事件與事件處理常式之間的關聯。
語法
RemoveHandler event, AddressOf eventhandler
組件
詞彙 | 定義 |
---|---|
event |
要處理之事件的名稱。 |
eventhandler |
目前正在處理事件之程序的名稱。 |
備註
AddHandler
與 RemoveHandler
陳述式可讓您在程式執行期間隨時啟動及停止特定事件的事件處理。
注意
針對自訂事件,RemoveHandler
陳述式會叫用事件的 RemoveHandler
存取子。 如需有關自訂事件的詳細資訊,請參閱 Event 陳述式。
範例
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