EventHandler

  • Thread starter Thread starter Matias Szulman
  • Start date Start date
M

Matias Szulman

Hi!
I need to know if an event (i.e. button1_click) has an eventhandler
associated. Is this possible in c#?

Thanks,

Matias
 
Matias,

It isn't really possible. What you would have to do is keep a record of
when the method is used for an event handler by overriding the event itself
to store when a method is used and even then, you can't override types
beyond your control to get that functionality.

What exactly are you trying to do?
 
I have a menu with menu items with different hierachies (for example, the
menus within outlook express). Now some of them have eventhandlers for some
events, but some don't (in OE, the MENU item in File does not have an
eventhandler for the click event, while the MESSAGE item under MENU under
FILE does have). I suppose it's hard to explain, but what I need to do is to
create a treenode with a node for each menu item that has en eventhandler
for the click event.

Thanks in advance,

Matias
 
Matias,
In addition to Nicholas's comments.
I need to know if an event (i.e. button1_click) has an eventhandler
associated. Is this possible in c#?
Are you asking does the Click event of the Button1 object have any handlers?

Remember that an event in implemented in terms of a Delegate. If the
Delegate is null there are no handlers, if the Delegate is not null there
are handlers.

http://msdn.microsoft.com/library/d...s/cpgenref/html/cpconeventusageguidelines.asp

If you are interested in the number of handlers, the Delegate has a
GetInvocationList method that returns the list of methods associated with
the delegate. Hence you can use GetInvocationList to get the number of
handlers associated with the event.

The problem you are going to run into, for classes that are not your own
design (Button for example) the above Delegate is private.

Hope this helps
Jay
 
Back
Top