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

What is the purpose of AddHandler keyword?

- The AddHandler statement allows you to specify an event handler.

- Addhandler associates an event with its handler at runtime.

- AddHandler has to be used to handle shared events or events from a structure.

The arguments passed to the Addhandler are:

a. The name of an event from an event sender.
b. An expression that evaluates to a delegate.

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.
   ' Stop handling events.
   RemoveHandler myObj.MyEvent, AddressOf MyEventHandler
   ' This event will not be handled.
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
Describe how exceptions are handled by the CLR - DOT.NET
Usually the exceptions that occur in the try are caught in the catch block....
How to throw a custom exception? - DOT.NET
The usual try - catch - finally - ent try format has to be followed....
What is the difference between Localization and Globalization? - DOT.NET
In Globalization, an application is developed to support various languages and cultures.....
Post your comment