Call a button on a C# form through usercontrol

后端 未结 4 2206
广开言路
广开言路 2021-01-23 18:37

I\'ve created a user control with some buttons. When you click a button in the UserControl the BackColor of the button changes:

 private void button1(object send         


        
4条回答
  •  梦谈多话
    2021-01-23 18:51

    You can get a reference to the parent form using this

    Form parentFrm = (this.Parent as Form);
    

    You can then access controls on the parent Form, by either making the public or finding the control by its name

     Button aButton = (Button)parentFrm.Controls["btnName"];
     if (aButton != null)
         aButton.Enabled = true;
    

提交回复
热议问题