Delegate events

别说谁变了你拦得住时间么 提交于 2019-12-10 16:15:49

问题


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.


回答1:


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);


来源:https://stackoverflow.com/questions/1753972/delegate-events

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!