EventHandler Generic Delegate
Assembly: mscorlib (in mscorlib.dll)
[SerializableAttribute] generic<typename TEventArgs> where TEventArgs : EventArgs public delegate void EventHandler ( Object^ sender, TEventArgs e )
The type of the event data generated by the event.
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 delegate that refers to a method that provides the response to the event.
A class that holds the event data.
The delegate is a type that defines a signature, that is, the return value type and parameter list types for a method. You can use the delegate type to declare a variable that can refer to any method with the same signature as the delegate.
The standard signature of an event handler delegate defines a method that does not return a value, whose first parameter is of type Object and refers to the instance that raises the event, and whose second parameter is derived from type EventArgs and holds the event data. If the event does not generate event data, the second parameter is simply an instance of EventArgs. Otherwise, the second parameter is a custom type derived from EventArgs and supplies any fields or properties needed to hold the event data.
EventHandler is a predefined delegate that represents an event handler method for an event, regardless of whether the event generates event data. If your event does not generate event data, substitute EventArgs for the generic type parameter; otherwise, supply your own custom event data type and substitute it for the generic type parameter.
The advantage of using EventHandler is that you do not need to code your own custom delegate if your event generates event data. Additionally, the .NET Framework needs only one implementation to support EventHandler regardless of the event data type you substitute for the generic type parameter.
To associate the event with the method that will handle the event, 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 (.NET Framework Guide).
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter EditionThe Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.