Winform 子窗口获取父窗口控件属性

在winform中打开的子窗口获取父窗口时,需要通过name来获取属性,比如text属性,需要通过构建父窗口的函数来实现。

 

1、在父窗口(MainViewContent)中(MainViewContent.cs)定义新的窗口变量:

 

然后在父窗口的函数中中添加

mainViewContent=this;

2、将需要调用的控件属性在MainViewContent.Desihner.cs中修改为public。

3、在子窗口中调用控件,使用MainViewContent.mainViewContent.控件名称.属性

 

posted @ 2022-04-06 11:53  草木同朽  阅读(804)  评论(0编辑  收藏  举报