问题描述:

I Have parent form(FORM1) and I added this code

FORM2 form = new FORM2();

form.Show();

what I want is to enable one specific button (which is disabled by default) when my child form is called(opened) from parent. Can you please give me example how to do it

网友答案:

You'll want to add a property like this one to your child form:

public bool MyButtonEnabled //TODO give better name
{
    get
    {
        //TODO change this to the button that you're using
        return button1.Enabled;
    }
    set
    {
        //TODO change this to the button that you're using
        button1.Enabled = value;
    }
}

You can then use that property from the parent form(s) to change the visibility of the button.

Using a property such as this is much better, from a design perspective, than exposing the button publicly as you limit the ability of external entities to do only what they need to without giving them way more access then they need.

相关阅读:
Top