开发者

Delegate events

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜