Nickeay

hi,

I am just thinking if there is a way to remove all handlers for an event, like
button1.Click += new MyEventHander(OnButton1Click);
button1.Click += new EventHandler(OnButton1StandardClick);
...
I think you can hook up as many as you want handlers to a single Click event. The question is how to remove all of them Is it the only way that remove one by one by using -=
Thanks.



Re: Visual C# General Is there anyway to clear all handlers for an event?

Mattias Sjogren

From outside the class, that's the only way. Inside the class providing the event you can simply set the delegate reference to null.






Re: Visual C# General Is there anyway to clear all handlers for an event?

Udhaya Kumar D


EventHandlerList eventsList = this.Events;
eventsList.Dispose();

Just removes all the events related to the Form or UserControl