Solved

control's event handler

Posted on 2012-03-24
10
350 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
ID: 37762709
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
ID: 37762741
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
ID: 37763001
Do you mean typeof(Button).GetType().GetEvents()?
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Author Comment

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

Expert Comment

by:Bob Learned
ID: 37765454
That would be slightly different:

button1.GetType().GetEvents()?

What do you to know from the EventInfo?
0
 

Author Comment

by:Mi-Jack
ID: 37765674
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
ID: 37765916
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
ID: 37766632
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
ID: 37766981
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
ID: 37767576
Thank you
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C# Single Form 8 42
Question! 4 36
converto datetime always changes format 9 35
Disable Security Alert  popup in Winforms  embedded webbrowser. 1 25
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

813 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