问题描述:有2UserControlUserControl1 里有一个ButtonUserControl2 里面有一个TextBox,这2个控件都加载到了主窗体Form1 上。要求的是,点击 UserControl1 button 显示 UserControl2TextBox输入的内容。 

一般来讲有2种方式:

1. 公开属性

2. 声明事件 

来看看这2种方式的操作代码:

1. 公开2个UserControl的属性。并在Form1中使用

public partial class UserControl1 : UserControl
    {
        public UserControl1()
        {
            InitializeComponent();
            
        }

        public Button Btn // Define Btn as public
        {
            get
            {
                return this.button1;
            }
        }    
    }
UserControl1

相关文章:

  • 2022-01-05
  • 2021-07-24
  • 2022-12-23
  • 2022-12-23
  • 2022-01-02
  • 2021-06-27
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-08
  • 2021-06-21
  • 2021-10-31
  • 2022-12-23
相关资源
相似解决方案