System Namespace
Represents the method that will handle the event that has no event data.
[ VB ]
Public Delegate Sub EventHandler ( _
ByVal sender As Object, _
ByVal e As EventArgs _
)
[ C# ]
public delegate void EventHandler (
object sender,
EventArgs e
);
[ C++ ]
public __gc __delegate void EventHandler (
Object* sender,
EventArgs* e
);
In [ JScript ], you can use the delegates in the .NET Framework, but you cannot define your own.
The declaration of your event handler must have the same parameters as the EventHandler delegate declaration.
- sender
- The source of the event.
- e
- An EventArgs that contains the event data.
The event model in the .NET Framework is based on having an event delegate that connects an event with its handler. To raise an event, two elements are needed:
- A class that holds the event data. This class must derive from the base class EventArgs.
- A delegate that points to a method that provides the response to the event.
If the event does not generate data, use the base class EventArgs for the event data object, and the pre-defined EventHandler for the event delegate.
When you create an EventHandler delegate, you identify the method that will handle the event. To associate the event with your event handler, add an instance of the delegate to the event. The event handler is called whenever the event occurs, unless you remove the delegate. For more information about event handler delegates, see Events and Delegates.
EventArgs Delegate