代表事件 [英] Delegate events
本文介绍了代表事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
您的用户控件内可以显示这样的控件B的事件...
public event EventHandler EventA
{
add {_control.EventB + = value; }
删除{_control.EventB - = value; }
}
您应该查看代理哪个事件B正在使用,并确保活动A比赛。在这个例子中,我刚刚选择了EventHandler,因为在开发User Controls时很常见。
public delegate void EventHandler(object sender,EventArgs e );
This is a C# question. I have a user control A. A contains another user control B. B has an event called BEvent. I want to expose this event in A so anyone who uses control A can subscribe BEvent. How can I write code to implement this design? Thanks.
解决方案
Inside your user control A you could expose the event of control B like this...
public event EventHandler EventA
{
add { _control.EventB += value; }
remove { _control.EventB -= value; }
}
You should look at the delegate which event B is using, and ensure that event A matches. In this example i just selected EventHandler because that is quite common when developing User Controls
public delegate void EventHandler(object sender, EventArgs e);
这篇关于代表事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文