Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / October 2005

Tip: Looking for answers? Try searching our database.

How does one remove Event Handlers?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Peter Oliphant - 06 Oct 2005 18:24 GMT
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?
Nishant Sivakumar - 06 Oct 2005 19:39 GMT
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.

Signature

Regards,
Nish [VC++ MVP]

> 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?
Peter Oliphant - 06 Oct 2005 21:51 GMT
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?

> 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.
[quoted text clipped - 3 lines]
>> this way? Or, just as good for my purposes, how can one remove all event
>> handlers attached?
Marcus Heege - 06 Oct 2005 21:55 GMT
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

> 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.
[quoted text clipped - 3 lines]
>> this way? Or, just as good for my purposes, how can one remove all event
>> handlers attached?

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.