Export (0) Print
Expand All

EventInfo.AddEventHandler Method

Adds an event handler to an event source.

[Visual Basic]
Public Sub AddEventHandler( _
   ByVal target As Object, _
   ByVal handler As Delegate _
)
[C#]
public void AddEventHandler(
 object target,
 Delegate handler
);
[C++]
public: void AddEventHandler(
 Object* target,
 Delegate* handler
);
[JScript]
public function AddEventHandler(
   target : Object,
 handler : Delegate
);

Parameters

target
The event source.
handler
Encapsulates a method or methods to be invoked when the event is raised by the target.

Exceptions

Exception Type Condition
InvalidOperationException The MethodInfo returned by GetAddMethod is a null reference (Nothing in Visual Basic).
ArgumentException The handler that was passed in cannot be used.
MethodAccessException The caller does not have access permission to the member.
TargetException The target parameter is a null reference (Nothing in Visual Basic) and the event is not static.

-or-

The EventInfo is not declared on the target.

Remarks

This method attempts to add a delegate to synchronize the event on the target object.Each time the event is raised by the target parameter, the method or methods encapsulated by the handler will be invoked.

Requirements

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, Common Language Infrastructure (CLI) Standard

.NET Framework Security: 

See Also

EventInfo Class | EventInfo Members | System.Reflection Namespace | Object | Delegate | EventHandler

Show:
© 2015 Microsoft