The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

AddHandler Statement

Associates an event with an event handler.

AddHandler event, AddressOf eventhandler


The name of the event to handle.
The name of a procedure that will handle the event.


The AddHandler and RemoveHandler statements allow you to start and stop event handling 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.
End Sub

Sub EventHandler()
   ' This procedure handles events raised by the object Obj.
   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

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

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft