event handler

  • Thread starter Thread starter bpfa
  • Start date Start date
bpfa said:
hi
there is a way to obtain the handler's list for a specific event of an
object?

thanks

I think only one handler can assign to one control's event? BTW, I don't
know much about C# yet, can you assign more than one handler to one
control's event?
 
.....
private Button btn;
.....

btn = new Button();
....
btn.Click += new EventHandler(OnClick);
btn.Click += new EventHandler(OnClick2);

......

private void OnClick(object sender, EventArgs e)
{
MessageBox.Show("OnClick");
}

private void OnClick2(object sender, EventArgs e)
{
MessageBox.Show("OnClick2");
}
 
FrzzMan said:
I think only one handler can assign to one control's event? BTW, I don't
know much about C# yet, can you assign more than one handler to one
control's event?

Absolutely. You might want various different methods to validate a
keystroke, for instance.
 
bpfa said:
there is a way to obtain the handler's list for a specific event of an
object?

Not from outside the class. From inside the class, assuming you've
implemented the event with a delegate (which you do by default with the
event keyword) you can use Delegate.GetInvocationList.
 
Thanks

Jon Skeet said:
Not from outside the class. From inside the class, assuming you've
implemented the event with a delegate (which you do by default with the
event keyword) you can use Delegate.GetInvocationList.
 
Back
Top