By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,512 Members | 3,790 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,512 IT Pros & Developers. It's quick & easy.

How does one remove Event Handlers?

P: n/a
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 one remove all event
handlers attached?
Nov 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
You could keep an ArrayList of all the delegates you've added to the event
and then remove them one by one using the -= operator.

--
Regards,
Nish [VC++ MVP]
"Peter Oliphant" <po*******@RoundTripInc.com> wrote in message
news:ey**************@TK2MSFTNGP12.phx.gbl...
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 one remove all event
handlers attached?

Nov 17 '05 #2

P: n/a
So, if i understand, I'd should do something like this (code inside a class,
hence the 'this' reference):

EventHandler* handler = new EventHandler( this, m_Handler ) ; //
this->m_Handler is of proper form

timer->Tick += handler ;

and then remove it via:

timer->Tick -= handler ; // this 'handler' is the same variable as above

Is this correct?

"Nishant Sivakumar" <ni**@nospam.asianetindia.com> wrote in message
news:Of*************@tk2msftngp13.phx.gbl...
You could keep an ArrayList of all the delegates you've added to the event
and then remove them one by one using the -= operator.

--
Regards,
Nish [VC++ MVP]
"Peter Oliphant" <po*******@RoundTripInc.com> wrote in message
news:ey**************@TK2MSFTNGP12.phx.gbl...
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 one remove all event
handlers attached?


Nov 17 '05 #3

P: n/a
I guess there is no need to keep an ArrayList of all the delegates you've
added. You can use MulticastDelegate::GetInvocationList to get an array of
all single cast delegates.

Marcus

"Nishant Sivakumar" <ni**@nospam.asianetindia.com> wrote in message
news:Of*************@tk2msftngp13.phx.gbl...
You could keep an ArrayList of all the delegates you've added to the event
and then remove them one by one using the -= operator.

--
Regards,
Nish [VC++ MVP]
"Peter Oliphant" <po*******@RoundTripInc.com> wrote in message
news:ey**************@TK2MSFTNGP12.phx.gbl...
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 one remove all event
handlers attached?


Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.