用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又怎么理解?
请各位帮我分析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又怎么理解?
如:按钮的位置、窗体的大小
就是每一个元件(控件)的属性
this理解为一个类的实例
因为一个类可以构建出无数的实例
每个实例就是通过this来知道自己是谁this.textBox1.Text = "hello";
textBox1.Text = "hello";
是等同的,textBox1.Text = "hello";相当于是一个简写
{
string str;
void Method(string str);
{
this.str = str;
}
}
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}