VB.NET - What is the purpose of AddHandler keyword?

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
VB.NET - how to implement globalization and localization in the use interface
How to implement globalization and localization in the use interface - Application use locale to identify the language and country of the user......
How to dynamically add items to a menu in .NET
How to dynamically add items to a menu in .NET
How to dynamically clone a menu in .NET
How to dynamically clone a menu in .NET
Post your comment