What is the purpose of AddHandler keyword?
Addhandler associates an event with its handler at runtime.
Example:Sub MyEvents()
Dim myObj As New MyClass
' Associate an event handler with an event.
AddHandler myObj.MyEvent, AddressOf MyEventHandler
' Call the method to raise the event.
myObj.ExecuteSomeEvent()
' Stop handling events.
RemoveHandler myObj.MyEvent, AddressOf MyEventHandler
' This event will not be handled.
myObj.ExecuteSomeEvent()
End Sub
Sub MyEventHandler()
' Handle the event.
MsgBox("MyEventHandler caught event.")
End Sub
Public Class MyClass
' Declare an event.
Public Event MyEvent()
Sub ExecuteSomeEvent()
' Raise an event.
RaiseEvent MyEvent()
End Sub
End Class