如何在winform窗体中动态生成常用的winform的控件呢?如textbox ,label 等

解决方案 »

  1.   

    TextBox tb = new TextBox();
                tb.Left = 10;
                tb.Top = 10;
                this.Controls.Add(tb);
      

  2.   

    打开窗体中的 private void InitializeComponent()方法看看就清楚了。如下:
                 ....
                // 
                // button1
                // 
                this.button1.Location = new System.Drawing.Point(229, 270);
                this.button1.Name = "button1";
                this.button1.Size = new System.Drawing.Size(75, 23);
                this.button1.TabIndex = 1;
                this.button1.Text = "button1";
                this.button1.UseVisualStyleBackColor = true;
                this.button1.Click += new System.EventHandler(this.button1_Click);
                // 
                // Form1
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(564, 429);
                this.Controls.Add(this.button1);
                this.Controls.Add(this.c1FlexGrid1);
                this.Name = "Form1";
                this.Text = "Form1";
         .....
      

  3.   

    Label lb = new Label();
    lb.Size = new Size(100,20);
    lb.Location = new Point(20,20);this.Controls.Add(lb);
      

  4.   

    恩,没错,拉个textbox放上去,看看系统自动生成的代码,照着敲就是了
      

  5.   

    TextBox[] tb = new TextBox[5];
    for(int i=0;i<5;i++)
    {
        tb[i]=new TextBox();
        tb[i].Width=80
        tb[i].Left = 30+90*i;
        tb[i].Top = 30;
        this.Controls.Add(tb[i]);
    }
      

  6.   

    如果控件不多,先放在指定位置,然后visiable = false,用的时候改为true就行了
      

  7.   

    哎,来迟一步,还接!
    如dugupiaoyun(独孤飘云) 所言。