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