Set / Clear and restore control event handlers

  • Thread starter Thread starter Lloyd Sheen
  • Start date Start date
L

Lloyd Sheen

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 (2008).

I would rather do things this way than having to have a boolean flag to
indicated to the handler to exit right away.

Psuedo code:

CacheHandlers(control)

code which would cause the control to fire an event.

RestoreHandlers(control).

LS
 
RemoveHandler ....
...

code which would cause the control to fire an event.

AddHandler ....
...
 
Stephany Young said:
RemoveHandler ....
...

code which would cause the control to fire an event.

AddHandler ....
...

Yes I know about the "norm" but what I am looking at doing is for a control
(any control) to have a way of removing and then after some code restoring
the event handlers. I am looking for a general method which would take into
account that I would not know what to use for Addhandler and RemoveHandler
so I am looking for a method to enumerate the "added" handlers and then
cache the info, do a remove and when asked reset using AddHandler.

LS
 
Lloyd,

You will need reflection for what you want, however in my idea are you going
in the wrong direction.

Cor
 
Michel Posseth said:
Seems pretty easy if this is what you are looking for :-)


http://msdn.microsoft.com/en-us/library/system.delegate.getinvocationlist.aspx


MyEventEvent.GetInvocationList()


HTH

Michel Posseth

Thanks but I would like to go from the other direction. I would like to get
a list of the eventhandlers (not eventinfo) for a control which would allow
me to remove the handlers from certain events and add them after I execute
some code. Is that at all possible?

I notice that Control thru the base class Component has a Events property.
This unfortunately is protected so I cannot get the list from here. I want
to start a control not at delegate since I might not know the delegate(s).

Thanks
LS
 
Back
Top