How to change component attributes between Forms? [duplicate]

0

I have a C # application with a parent Form (FRM_PRINCIPAL) that contains a button (BTN_ACT) that calls a child Form (Form2), which in turn contains a button (BTN_REG) containing some functions, the BTN_ACT in invisible (BTN_ACT.Visible = False;). How would I do that? To simplify: Basically make the button of the first Form invisible through the button of a second Form.

    
asked by anonymous 01.08.2014 / 03:14

1 answer

2

In your FRM_PRINCIPAL, you need to create a public method to set the visibility of your button.

public void AlteraVisibilidadeBtnAct(bool visivel)
{
    this.BTN_ACT.Visible = visivel;
}

In the click method of your BTN_REG button, you call the method created above as follows if Form2 is the child of your FRM_PRINCIPAL. One form is child of the other when the MdiParent property is set to the child.

private void BTN_REG_Click(object sender, System.EventArgs e)
{
    ParentForm.AlteraVisibilidadeBtnAct(false);
}

If Form2 is not a child of FRM_PRINCIPAL, you must add FRM_PRINCIPAL to the Form2 constructor, then access it in the click event.

private FRM_PRINCIPAL frmPrincipal;

public Form2(FRM_PRINCIPAL frmPrincipal)
{
    this.frmPrincipal = frmPrincipal;
}

private void BTN_REG_Click(object sender, System.EventArgs e)
{
    frmPrincipal.AlteraVisibilidadeBtnAct(false);
}
    
01.08.2014 / 07:23