Possible Duplicate: How would that be possible to remove all event handlers of the Click event of a Button?
I want to remove all click event handlers from a button. I found this method in Stack Overflow question How to remove all event handlers from a control.
private void RemoveClickEvent(Button b)
{
FieldInfo f1 = typeof(Control).GetField("EventClick",
BindingFlags.Static |
BindingFlags.NonPublic);
object obj = f1.GetValue(b);
PropertyInfo pi = b.GetType().GetProperty("Events",
BindingFlags.NonPublic |
BindingFlags.Instance);
EventHandlerList list = (EventHandlerList)pi.GetValue(b, null);
list.RemoveHandler(obj, list[obj]);
}
But this line always returns null:
typeof(Control).GetField("EventClick", BindingFlags.Static | BindingFlags.NonPublic);
And this method was written in 2006.
Is there any latest version of this method?