RemoveHandler Statement
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

RemoveHandler Statement

Removes the association between an event and an event handler.

RemoveHandler event, AddressOf eventhandler


The name of the event being handled.
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.


Sub TestEvents()
   Dim Obj As New Class1()
   ' Associate an event handler with an event.
   AddHandler Obj.Ev_Event, AddressOf EventHandler
   Obj.CauseSomeEvent() ' Ask the object to raise an event.
   RemoveHandler Obj.Ev_Event, AddressOf EventHandler ' Stop handling events.
   Obj.CauseSomeEvent() ' This event will not be handled.
End Sub

   Sub EventHandler()
      MsgBox("EventHandler caught event.") ' Handle the event.
   End Sub

Public Class Class1
   Public Event Ev_Event()  ' Declare an event.
   Sub CauseSomeEvent()
      RaiseEvent Ev_Event() ' Raise an event.
   End Sub
End Class

See Also

AddHandler Statement | Handles | Events and Event Handlers | AddHandler and RemoveHandler

© 2015 Microsoft