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
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,

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"
Mi-JackAuthor Commented:
I have a variable of type Button, and I need to find out its OnClick EventHandler(s)
Bob LearnedCommented:
Do you mean typeof(Button).GetType().GetEvents()?
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

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


What do you to know from the EventInfo?
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 >);
Bob LearnedCommented:
Where do you need to do this?  Do you have a reference to the control, and you need to do it dynamically?
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.
Bob LearnedCommented:
That is possible with reflection.  The steps are shown in the code from this CodeProject article:

Removing Event Handlers using Reflection

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
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

From novice to tech pro — start learning today.