I have a code like:
button1.Click += (s, e) =>
{
};
Now how is it possible to remove this handler dynamically? something like:
button1.Click = null;
I have a code like:
button1.Click += (s, e) =>
{
};
Now how is it possible to remove this handler dynamically? something like:
button1.Click = null;
The point with events is that they are subscribe/unsubscribe, it is not the intention that you should unsubscribe other events then your own. Therefore you need to keep track of your event:
var click = (s, e) =>
{
};
button1.Click += click;
You can then unsubscribe it by:
button1.Click -= click;
EDIT
Seems you can use the approach suggested here.