在 c# 中的用户控件中公开和引发子控件的事件 [英] expose and raise event of a child control in a usercontrol in c#

查看:24
本文介绍了在 c# 中的用户控件中公开和引发子控件的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.我有一个包含文本框的 UserControl.我想访问文本框的 textchanged 事件,但在用户控件的事件属性中,我没有看到文本框的事件.如何使用 C# 在 Winforms 中公开和处理来自公开公开的 UserControl 的子控件的特定事件.

Hi. I have a UserControl which contains a textbox. I wanted to access the textchanged event of the textbox but in the event properties of the usercontrol I don't see the events for the textbox. How can I expose and handle particular events of the child controls from the publicly exposed UserControl in Winforms with C#.

推荐答案

如果您愿意,您可以显示新事件并将任何订阅直接传递给控件:

You can surface a new event and pass any subscriptions straight through to the control, if you like:

public class UserControl1 : UserControl 
{
    // private Button saveButton;

    public event EventHandler SaveButtonClick
    {
        add { saveButton.Click += value; }
        remove { saveButton.Click -= value; }
    }
}

这篇关于在 c# 中的用户控件中公开和引发子控件的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆