Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我可以访问表单上的控制变量吗?例如:
MyForm form = new MyForm(); form.button1.Visible = True; // why doesn't this work?
您需要通过属性窗口设置public或internal修改控件或打开 Designer.cs 并设置访问修饰符。Modifier
public
internal
Modifier
bool SearchAllChildren = true; (this.Controls.Find("button1", SearchAllChildren )[0] as Button).Visible = true;
您可以设置SearchAllChildren为false仅返回表单上的控件而不是嵌套控件(其他控件中的控件)
SearchAllChildren
false