Get event which call method

  • Thread starter Klaudiusz Bryja
  • Start date
K

Klaudiusz Bryja

Hi,

I need to get event name which call method. How do I do this? For
example - I have button with subscribed Click event and e.g. GotFocus.
For both this events I have the same method which consume this event
(let's say eventOccured). In eventOccured method I need to get
information which event occured.

E.g. when I click on button I get in eventOccured that was fired by
Click event.

Is it possible to get this info? How to do this?

Best regards,
Klaudiusz
 
M

Marc Gravell

Well, a grungy way would be to walk the stack, but I'd just forward the
event-handlers to the inner method along with the extra info:

foo.Click += delegate {EventOccurred("Click");};
foo.GotFocus += delegate {EventOccurred("GotFocus");};

Where those strings could just as easily be an enum, and we could
optionally pass in the sender/args etc...

Marc
 
K

Klaudiusz Bryja

Well, a grungy way would be to walk the stack, but I'd just forward theevent-handlers to the innermethodalong with the extra info:

foo.Click += delegate {EventOccurred("Click");};
foo.GotFocus += delegate {EventOccurred("GotFocus");};

Where those strings could just as easily be an enum, and we could
optionally pass in the sender/args etc...

Marc

Hi,

Thanks. It works perfect.

Klaudiusz
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top