?
Solved

control's event handler

Posted on 2012-03-24
10
Medium Priority
?
357 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

764 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