0

kinda difficult to explain but is there a way to do something like:

control1.ShownEditor += EventHandler;

...

control2.ShownEditor += control1.ShownEditor; //wrong
Mauro
  • 2,032
  • 3
  • 25
  • 47

3 Answers3

2

Save your event to a EventHandler delegate.

EventHandler Myevent = () => {/*event handling code here*/};

Assign the event handler delegate to the control events

control1.ShownEditor += Myevent;
control2.ShownEditor += Myevent;
Prabhu Murthy
  • 9,031
  • 5
  • 29
  • 36
2

I think you need something like this to get bound EventHandler. As you have handler, you can then easily bind it to event.

tukaef
  • 9,074
  • 4
  • 29
  • 45
1

Simply: you cannot use an EventHandler of a control's event and assign it to another event. So this isn't possible:

control2.ShownEditor += control1.ShownEditor; //wrong

The only way is to create an EventHandler separately and assign it to both the controls' event.

Another harmful solution could be extract the delegate via Reflection, but as I said it's actually dangerous, look this answer by Hans Passant: Is it possible to “steal” an event handler from one control and give it to another?.

Community
  • 1
  • 1
Omar
  • 16,329
  • 10
  • 48
  • 66