473,387 Members | 1,318 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to clear up all attached event handlers.

zlf
I have an UserControl created by other component, its creator attachs some
event handlers to MouseDoubleClick event, but I do not like those events to
be triggered while it is db-clicked. I want to know how to clear up them?
Thanks

BTW: I do not know what specific event handlers are attached, so I cannot
use Banner_MouseDoubleClick -= XXX to unregister it.
Jun 13 '07 #1
5 25709
If you want to clear all you can just assign null ot event ...
otherwise you can use
Delegate.GetInvocationList() and then Method & Target property to get
MethodInfo of each method.

"zlf" <zl***@hotmail.comwrote in message
news:eP*************@TK2MSFTNGP02.phx.gbl...
>I have an UserControl created by other component, its creator attachs some
event handlers to MouseDoubleClick event, but I do not like those events to
be triggered while it is db-clicked. I want to know how to clear up them?
Thanks

BTW: I do not know what specific event handlers are attached, so I cannot
use Banner_MouseDoubleClick -= XXX to unregister it.

Jun 13 '07 #2
zlf
userControl.MouseDoubleClick = null leads to compile error.
The event 'System.Windows.Forms.Control.MouseDoubleClick' can only appear on
the left hand side of += or -=.
And I tried userControl.MouseDoubleClick += null, it does not clear up the
attached event handlers.

May u give a simple statement? Thx

"Daniel Cigic" <da**********@gmail.comдÈëÏûÏ¢ÐÂÎÅ:ur************ **@TK2MSFTNGP03.phx.gbl...
If you want to clear all you can just assign null ot event ...
otherwise you can use
Delegate.GetInvocationList() and then Method & Target property to get
MethodInfo of each method.

"zlf" <zl***@hotmail.comwrote in message
news:eP*************@TK2MSFTNGP02.phx.gbl...
>>I have an UserControl created by other component, its creator attachs some
event handlers to MouseDoubleClick event, but I do not like those events
to be triggered while it is db-clicked. I want to know how to clear up
them? Thanks

BTW: I do not know what specific event handlers are attached, so I cannot
use Banner_MouseDoubleClick -= XXX to unregister it.


Jun 13 '07 #3
Daniel Cigic <da**********@gmail.comwrote:
If you want to clear all you can just assign null ot event ...
otherwise you can use
Delegate.GetInvocationList() and then Method & Target property to get
MethodInfo of each method.
Strictly speaking, you can't do any of these things for an event. You
*can* do them for delegates - the two are different.

Field-like events in C# (i.e. the ones you get with simple
public event EventHandler Foo;
) create both an event and a field of the relevant delegate type
(EventHandler here). Within the class, any reference to Foo is a
reference to the field. Outside the class, any reference to Foo is a
reference to the event.

Events only have add/remove, a bit like properties only have get/set.
In other words, you can't perform assignment on them, nor get their
invocation lists.

See http://pobox.com/~skeet/csharp/events.html for more information

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jun 13 '07 #4
zlf <zl***@hotmail.comwrote:
userControl.MouseDoubleClick = null leads to compile error.
The event 'System.Windows.Forms.Control.MouseDoubleClick' can only appear on
the left hand side of += or -=.
And I tried userControl.MouseDoubleClick += null, it does not clear up the
attached event handlers.
The point of an event is to encapsulate the event handling so that
callers from the outside can only subscribe and unsubscribe. If this
were a custom event you were creating in your user control, you could
expose the ability to clear it - but if it's an event inherited from
Control, then unless Control provides a way of clearing the event
handlers, you're out of luck. (You could use reflection potentially,
but that would be very fragile - any change to the implementation would
screw up your application.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jun 13 '07 #5
Thanks Jon, I thought that zlf was "in the class" and in that case it would
be possible to get invocation list.

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP*********************@msnews.microsoft.com. ..
Daniel Cigic <da**********@gmail.comwrote:
>If you want to clear all you can just assign null ot event ...
otherwise you can use
Delegate.GetInvocationList() and then Method & Target property to get
MethodInfo of each method.

Strictly speaking, you can't do any of these things for an event. You
*can* do them for delegates - the two are different.

Field-like events in C# (i.e. the ones you get with simple
public event EventHandler Foo;
) create both an event and a field of the relevant delegate type
(EventHandler here). Within the class, any reference to Foo is a
reference to the field. Outside the class, any reference to Foo is a
reference to the event.

Events only have add/remove, a bit like properties only have get/set.
In other words, you can't perform assignment on them, nor get their
invocation lists.

See http://pobox.com/~skeet/csharp/events.html for more information

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Jun 13 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: tony kulik | last post by:
This code works fine in ie and opera but not at all in Mozilla. Anybody got a clue as to how to get it right? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <script...
1
by: MuZZy | last post by:
Hi, Is there a way to remove all event handlers for a control's event? Say, i have a button and i want to remove all button.Click events for it - i don't know how many of them was hooked to the...
3
by: Peter Oliphant | last post by:
In general, some controls can have events handlers attached to them, typically via the += operator. How does one remove an event handler added this way? Or, just as good for my purposes, how can...
13
by: Charles Law | last post by:
Mr "yEaH rIgHt" posted the following link about a week ago in answer to my question about removing event handlers. > http://www.vbinfozine.com/t_bindevt.shtml Following on from that post, the...
7
by: Michael D. Ober | last post by:
Is there anyway to raise an event from a class and require that any program using that class (not just inheritance) have an event handler for specific events in the class? In my case, some events...
2
by: Safalra | last post by:
Recently I've rewritten much of my old Javascript code to use DOM functions so that enhancements can be attached to documents without needing to alter the HTML code. I assumed that adding event...
0
by: zlf | last post by:
I have an UserControl created by other component, its creator attachs some event handlers to MouseDoubleClick event, but I do not like those events to be triggered while it is db-clicked. I want to...
2
by: Claire | last post by:
Hi, Pardon my poor description ahead, I don't know the technical terms. If I add an event to an event handler from a class that later goes "dead" without being disposed, what happens when the...
5
by: Lloyd Sheen | last post by:
Is there a way to get the event handlers such that I can cache the info about handlers for a particular control, remove the handlers, do some code and restore the cached event handlers in VB.NET...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.