再简单不过的问题,在static类型的函数中,如何在控件上显示信息? private System.Windows.Forms.Label label1;public static void test(){ this.label1.Text = "text !";} 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 对,如果用如下代码:public static void test(){ this.label1.Text = "text !";}出错信息是:E:\winform\Start\Form1.cs(168): 关键字 this 在静态属性、静态方法或静态字段初始值设定项中无效如果用如下代码:public static void test(){ label1.Text = "text !";}出错信息是:E:\winform\Start\Form1.cs(168): “Start.Form1.label1”表示“字段”,此处应为“类”。 (new 该类的名字()).label1.Text = "text !"; private System.Windows.Forms.Label label1;public static void test(Label _label1){ _label1.Text = "text !";} JasonHeung,您好,这样做是可以,但因为我要用的是线程中,而test()又不能带参数。private System.Windows.Forms.Label label1;thread = new Thread(new ThreadStart(x.test));public static void test(Label _label1){ _label1.Text = "text !";}Jb303,您好,为了适应于线程中,不要带参数。应该怎么做?(new 该类的名字()).label1.Text = "Text !";中的“该类的名字”,是指哪一个类呢?谢谢。 (new Form1()).label1.Text = "111111";这样写,编译通过,但是不能显示出结果。 也就是说:public static void test(Label _label1){ _label1.Text = "text !";}可以正确显示。public static void test(){ (new Form1()).label1.Text = "111111";}什么都不显示。 public static void Main(){Form1 f = new Form1();f.label1.Text = "1111";//尽管这样可以,但不好,最好通过方法给一个类的私有变量赋值Application.Run(f);} 二维数组的问题 DateTime 类型变量的实例化问题 C#中对datatable的一些操作,80分请教 vs2005怎么生成DLL文件 没有入口点 有人能搞定吗?再来一贴:为什么System.Environment.后面没有SpecialFolder?我新建一个项目后又能找到SpecialFolder了?好奇怪!急急急 C#制作控件的2个问题 帮看一下,那样的设计好,关于和“内存”的选择? Datatable合并行,列值累加 如何捕获定时器中的异常? 看看这个程序,如何让上传的文件.... 求关于星期的算法
如果用如下代码:
public static void test()
{
this.label1.Text = "text !";
}
出错信息是:
E:\winform\Start\Form1.cs(168): 关键字 this 在静态属性、静态方法或静态字段初始值设定项中无效如果用如下代码:
public static void test()
{
label1.Text = "text !";
}
出错信息是:
E:\winform\Start\Form1.cs(168): “Start.Form1.label1”表示“字段”,此处应为“类”。
public static void test(Label _label1)
{
_label1.Text = "text !";
}
private System.Windows.Forms.Label label1;
thread = new Thread(new ThreadStart(x.test));public static void test(Label _label1)
{
_label1.Text = "text !";
}
Jb303,您好,为了适应于线程中,不要带参数。应该怎么做?
(new 该类的名字()).label1.Text = "Text !";
中的“该类的名字”,是指哪一个类呢?
谢谢。
这样写,编译通过,但是不能显示出结果。
public static void test(Label _label1)
{
_label1.Text = "text !";
}
可以正确显示。
public static void test()
{
(new Form1()).label1.Text = "111111";
}
什么都不显示。
{
Form1 f = new Form1();
f.label1.Text = "1111";//尽管这样可以,但不好,最好通过方法给一个类的私有变量赋值
Application.Run(f);}