control's event handler

Hi all,

I have a variable of type Button that I get from a call back on a form.
Just having this variable, is there a way to find the button's Click event
handler?
Just to be clear - when I assign it myself, like so:

Button b = new Button();
b.Click += new EventHandler(this.button_Click);

I obviously know that button_Click function gets called -
that's what I need to find out for the variable.

Thank you,

Gene
Mi-JackAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
I don't understand your question, and what you mean by "that's what I need to find out for the variable"
0
Mi-JackAuthor Commented:
I have a variable of type Button, and I need to find out its OnClick EventHandler(s)
0
Bob LearnedCommented:
Do you mean typeof(Button).GetType().GetEvents()?
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Mi-JackAuthor Commented:
I mean that particular Button reference to which I have, not Button as a class
0
Bob LearnedCommented:
That would be slightly different:

button1.GetType().GetEvents()?

What do you to know from the EventInfo?
0
Mi-JackAuthor Commented:
Looks like I'm getting EventHandlerType, but not an EventHandler handler, so I could remove an event, like this:

button1.Click -= new EventHandler(<EventHandler >);
0
Bob LearnedCommented:
Where do you need to do this?  Do you have a reference to the control, and you need to do it dynamically?
0
Mi-JackAuthor Commented:
The control is in a dll.
By iterating the Controls collection, I find the control I need, and I need to replace the control's Click EventHandler with my own.
0
Bob LearnedCommented:
That is possible with reflection.  The steps are shown in the code from this CodeProject article:

Removing Event Handlers using Reflection
http://www.codeproject.com/Articles/103542/Removing-Event-Handlers-using-Reflection
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mi-JackAuthor Commented:
Thank you
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.