Solved

control's event handler

Posted on 2012-03-24
10
347 Views
Last Modified: 2012-03-26
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
0
Comment
Question by:Mi-Jack
  • 5
  • 5
10 Comments
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
I don't understand your question, and what you mean by "that's what I need to find out for the variable"
0
 

Author Comment

by:Mi-Jack
Comment Utility
I have a variable of type Button, and I need to find out its OnClick EventHandler(s)
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
Do you mean typeof(Button).GetType().GetEvents()?
0
 

Author Comment

by:Mi-Jack
Comment Utility
I mean that particular Button reference to which I have, not Button as a class
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
That would be slightly different:

button1.GetType().GetEvents()?

What do you to know from the EventInfo?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Mi-Jack
Comment Utility
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
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
Where do you need to do this?  Do you have a reference to the control, and you need to do it dynamically?
0
 

Author Comment

by:Mi-Jack
Comment Utility
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
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
Comment Utility
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
 

Author Comment

by:Mi-Jack
Comment Utility
Thank you
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now