C# 如何在 其它类中改主窗体Form 控件的值 解决方法

博主被这个问题虐了半个多小时,自己默默看语法,测试数次无果,经大神指点遂懂之,特献分享。

测试环境:VS2013    .NET4.5 Windows 8.1

主窗体类:Form1  需修改Form1 上 Label1.Text

第三方类:class otherclass;

问题如上:“C# 如何在 其它类中改主窗体Form 控件的值”

解决办法:

1、在主窗体中声明一静态Lable

 label_static

public static System.Windows.Forms.Label label_static = new System.Windows.Forms.Label();

2、在Form1 构造函数中 加入:

label_static =this.label1;

3、然后在第三方类 otherclass中就可以通过改

label_static

而间接修改Form1上的label1了。

如:

Form1.label_static.Text= "Listening...";

有问题烦请大家指出~