System.EventHandler Delegate

Assembly: Mscorlib.dll
Namespace: System
Summary
Represents the method that will handle the event that has no event data.
C# Syntax:
[Serializable]
public delegate void EventHandler(object sender, EventArgs e);
Parameters:
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.

Remarks
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:

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 the conceptual topic at MSDN: eventsdelegates.

Example
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.
public delegate void EventHandler(Object sender, EventArgs e);

public event EventHandler NoDataEventHandler;

    
See also:
System Namespace | EventArgs | Delegate | MSDN: eventsdelegates

Hierarchy:

Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.