当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Enable child form button

问题描述:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: