请问C#中怎么用代码将控件写到窗体上,例如我要将Label控件写到窗体上,并赋值要怎么写?
我写的是 Label l=new Label();  l.Text="aaa";    
但是这样没有效果。请教名位!!!

解决方案 »

  1.   

    RichTextBox  richTextBox1 = new System.Windows.Forms.RichTextBox();
     this.richTextBox1.Location = new System.Drawing.Point(0, 345);
                this.richTextBox1.Name = "richTextBox1";
                this.richTextBox1.Size = new System.Drawing.Size(252, 180);
                this.richTextBox1.TabIndex = 0;
                this.richTextBox1.Text = "";
      

  2.   

    楼主要注意观察VS自动生成的代码,你会发现其实所有的东西都是由相应的代码来控制的哦  this.groupBox1 = new System.Windows.Forms.GroupBox();
      this.groupBox1.Location = new System.Drawing.Point(12, 63);
      this.groupBox1.Name = "groupBox1";
      this.groupBox1.Size = new System.Drawing.Size(166, 123);
      this.Controls.Add(this.groupBox2);
      

  3.   

    Label  label = new System.Windows.Forms.Label();
    label.Location = new System.Drawing.Point(150, 0);
    label.Name = "label";
    label.Size = new System.Drawing.Size(23,12);
    label.Text = "";this.controls.add(label);
      

  4.   

    加上这一句~  this.Controls.Add(l);