3

I have a code like:

button1.Click += (s, e) =>
{

};

Now how is it possible to remove this handler dynamically? something like:

button1.Click = null;
Ashkan Mobayen Khiabani
  • 32,319
  • 30
  • 98
  • 161

1 Answers1

4

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.

Community
  • 1
  • 1
Simon Karlsson
  • 3,992
  • 19
  • 38