Home > Mobile >  Open a panel of the form inside the usercontrol
Open a panel of the form inside the usercontrol

Time:03-28

I'm trying to open a Panel that is in the main form (form1) from a button that is inside a UserControl , but the code runs but does not enable the panel of the main form Can you help me?

//UserControl code
private void BtnChangeStatusOrder_Click(object sender, EventArgs e)
    {
        Button seta = (Button)sender;
        var form = new Form1();
        form.EnabledPanel1(seta.Tag.ToString());
    }

//main form code
    public void EnabledPanel(string order)
        {
          
            panel1.Visible = true;
        }

CodePudding user response:

Assuming the UserControl is also contained by Form1, then you can use TopLevelControl to get a reference to the Form:

private void BtnChangeStatusOrder_Click(object sender, EventArgs e)
{
    Button seta = (Button)sender;
    Form1 f1 = (Form1)this.TopLevelControl;
    f1.EnabledPanel1(seta.Tag.ToString());
}

*Why does EnabledPanel() receive a string?

  • Related