In C#, you can do as follows:
// Use a custom Delegate to hold your subscribers
private EventHandler myHandlers;
// Control Click event firing, for example.
public new event EventHandler Click
{
add
{
this.myHandlers += value;
}
remove
{
this.myHandlers -= value;
}
}
protected override void OnClick(EventArgs e)
{
// First let my derived classes receive the Click event.
foreach(Delegate d in this.myHandler.GetInvocationList())
{
if(d.Target == this)
{
d.DynamicInvoke(new object[]{this, e});
break;
}
}
// Then let other subscribers receive the Click event.
foreach(Delegate d in this.myHandler.GetInvocationList())
{
if(d.Target != this)
d.DynamicInvoke(new object[]{this, e});
}
}
Share with