This documentation is archived and is not being maintained.

EventHandler Delegate

Represents the method that will handle the event that has no event data.

[Visual Basic]
Public Delegate Sub EventHandler( _
   ByVal sender As Object, _
   ByVal e As EventArgs _
public delegate void EventHandler(
   object sender,
   EventArgs e
public __gc __delegate void EventHandler(
   Object* sender,
   EventArgs* e

[JScript] In JScript, you can use the delegates in the .NET Framework, but you cannot define your own.

Parameters [Visual Basic, C#, C++]

The declaration of your event handler must have the same parameters as the EventHandler delegate declaration.

The source of the event.
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.


[Visual Basic, C#, C++] A declaration for a no-data event delegate is shown below, where EventHandler is the pre-defined event delegate, sender is the object that raises the event, and e is the event data object that contains no data. The second line defines the event member in your class for the no-data event.

[Visual Basic] 
Delegate Sub EventHandler(sender As Object, e As EventArgs)
Public Event NoDataEventHandler As EventHandler

public delegate void EventHandler(Object sender, EventArgs e);

public event EventHandler NoDataEventHandler;

__delegate void EventHandler(Object* sender, EventArgs* e);

__event EventHandler* NoDataEventHandler;

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Namespace: System

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

Assembly: Mscorlib (in Mscorlib.dll)

See Also

System Namespace | EventArgs | Delegate | Events and Delegates