RemoveHandler 语句RemoveHandler Statement

删除事件和事件处理程序之间的关联。Removes the association between an event and an event handler.


RemoveHandler event, AddressOf eventhandler  


术语Term DefinitionDefinition
event 正在处理的事件的名称。The name of the event being handled.
eventhandler 当前处理事件的过程的名称。The name of the procedure currently handling the event.


使用 AddHandlerRemoveHandler 语句,可以在程序执行过程中随时启动和停止特定事件的事件处理。The AddHandler and RemoveHandler statements allow you to start and stop event handling for a specific event at any time during program execution.


对于自定义事件,RemoveHandler 语句调用事件的 RemoveHandler 访问器。For custom events, the RemoveHandler statement invokes the event's RemoveHandler accessor. 有关自定义事件的详细信息,请参阅Event 语句For more information on custom events, see Event Statement.


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.
    ' Stop handling events.
    RemoveHandler Obj.Ev_Event, AddressOf EventHandler
    ' This event will not be handled.
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