Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting event handler from event? [duplicate]

Possible Duplicate:
Is it possible to “steal” an event handler from one control and give it to another?

Is there a way to get references of the event handlers from the event?

For example:

EventHandler evt = btn.Click; // or another way ?

(Here the EventHandler is the delegate and Click is an event of Button)

like image 644
Brij Avatar asked Oct 09 '12 13:10

Brij


1 Answers

If you defined the event and your code that accesses it is in the same class (i.e. not derived) then you can access it and get the invocation list.

MulticastDelegate m = (MulticastDelegate)MyEvent;  

var list = m.GetInvocationList();  

foreach(Delegate d in list)  
{  
    // look at the delegate
}  
  • http://www.c-sharpcorner.com/UploadFile/rmcochran/csharp_events01292006081130AM/csharp_events.aspx

  • http://social.msdn.microsoft.com/Forums/eu/csharplanguage/thread/9a58321d-7fd5-45ca-bba0-44a0a336aeeb

For the case where you want to access the invocation list of an event defined in a class whose code you can't modify...

  • C# How to find if an event is hooked up
like image 122
CSmith Avatar answered Oct 10 '22 19:10

CSmith