Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
RemoveHandler Statement

RemoveHandler Statement

Removes the association between an event and an event handler.

RemoveHandler event, AddressOf eventhandler

event

The name of the event being handled.

eventhandler

The name of the procedure currently handling the event.

The AddHandler and RemoveHandler statements allow you to start and stop event handling for a specific event at any time during program execution.

For custom events, the RemoveHandler statement invokes the event's RemoveHandler accessor. 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.
    Obj.CauseSomeEvent()
    ' Stop handling events. 
    RemoveHandler Obj.Ev_Event, AddressOf EventHandler
    ' This event will not be handled.
    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
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()
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

Community Additions

ADD
Show:
© 2015 Microsoft