// Bind an event for button1Program
Button BTN = new button ();
BTN. Click + = new eventhandler (button2_click );
// Obtain information about all events defined by the button class
Propertyinfo Pi = (typeof (button). getproperty ("Events", bindingflags. instance | bindingflags. nonpublic );
// Obtain the list of event handlers of the button object BTN
Eventhandlerlist EHL = (eventhandlerlist) PI. getvalue (BTN, null );
// Obtain the field information of the control Click Event
Fieldinfo = (typeof (Control). getfield ("eventclick", bindingflags. Static | bindingflags. nonpublic );
// Match the event handler list of the BTN object with the field information of the obtained click event to obtain the delegate object of the BTN object Click Event
// The event is defined by the delegate. The multicast delegate in C # can be bound to multiple event handlers. when an event occurs, these event handlers are executed in sequence.
// Therefore, the delegate object has a getinvocationlist method to obtain all the Event Handlers bound to this delegate.
Delegate d = EHL [fieldinfo. getvalue (null)];
Foreach (delegate del in D. getinvocationlist ())
{
// Determine whether an event handler has been bound to a click event
Console. writeline (Del. method. Name = "button#click ");
}
Private void button#click (Object sender, eventargs E)
{
MessageBox. Show ("Hello, button#click ");
}
Private void button2_click (Object sender, eventargs E)
{
MessageBox. Show ("Hello, button2_click ");
}