用vs2005新建一个简单的项目,在Form1.cs[设计]中添加一个label1控件;
请各位帮我分析Designer文件中几个语句,谢谢!:
1) Form1.Designer.cs结尾处有 private System.Windows.Forms.Label label1;语句:我认为是在System.Windows.Forms空间中创建了Label类的一个label1对象;但在InitializeComponent()方法中有一条this.label1=new System.Windows.Forms.Label();语句,请语句中this代表什么,this.label1又怎么理解?

解决方案 »

  1.   

    private System.Windows.Forms.Label label1; 只是声明或者说是定义this.label1=new System.Windows.Forms.Label(); 才是创建对象
      

  2.   

    label1声明的是Lable类的对象变量,那创建label1对象时,this是不是能理解为Lable类?
      

  3.   

    Designer顾名思义 就是保存设计期间用户设置的信息
    如:按钮的位置、窗体的大小
    就是每一个元件(控件)的属性
    this理解为一个类的实例
    因为一个类可以构建出无数的实例
    每个实例就是通过this来知道自己是谁this.textBox1.Text = "hello";
    textBox1.Text = "hello";
    是等同的,textBox1.Text = "hello";相当于是一个简写
      

  4.   

    this是可去掉的,原则上就应该去掉的。在下面情况下就必须用到this了:class....
    {
      string str;
      void Method(string str);
     {
        this.str = str;
      }
    }
      

  5.   

    可以理解为:
    private System.Windows.Forms.Label label1=new System.Windows.Forms.Label(); this = Form1//Type type = this.GetType();
    //type {Name = "Form1" FullName = "WindowsApplication1.Form1"} System.Type {System.RuntimeType}