private System.Windows.Forms.Label label1;
public static void test()
{
  this.label1.Text = "text !";
}

解决方案 »

  1.   

    对,
    如果用如下代码:
    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”表示“字段”,此处应为“类”。
      

  2.   

    (new 该类的名字()).label1.Text = "text !";
      

  3.   

    private System.Windows.Forms.Label label1;
    public static void test(Label _label1)
    {
      _label1.Text = "text !";
    }
      

  4.   

    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 !";
    中的“该类的名字”,是指哪一个类呢?
    谢谢。
      

  5.   

    (new Form1()).label1.Text = "111111";
    这样写,编译通过,但是不能显示出结果。
      

  6.   

    也就是说:
    public static void test(Label _label1)
    {
    _label1.Text = "text !";
    }
    可以正确显示。
    public static void test()
    {
    (new Form1()).label1.Text = "111111";
    }
    什么都不显示。
      

  7.   

    public static void Main()
    {
    Form1 f = new Form1();
    f.label1.Text = "1111";//尽管这样可以,但不好,最好通过方法给一个类的私有变量赋值
    Application.Run(f);}