我想创建一个带有按钮的表单,其中按钮可以创建一组组件(2个文本框,1个标签)。我希望在文本框中输入的值存储到int数组中。
我做到了这一点 按钮单击事件
private void button1_Click(object sender, EventArgs e)
{
AddNewLabel();
AddNewTextBox1();
AddNewTextBox2();
}
添加文本框
public System.Windows.Forms.TextBox AddNewTextBox1()
{
System.Windows.Forms.TextBox txt1 = new System.Windows.Forms.TextBox();
this.Controls.Add(txt1);
txt1.Top = txtBoxCounter * 28;
txt1.Left = 125;
string txtName1 = "txtLL" + txtBoxCounter;
txt1.Name = txtName1;
string txtValue1 = txt1.Text;
lowerLimit[txtBoxCounter-1] = Int32.Parse(txtValue1);
return (txt1);
}
添加标签
public System.Windows.Forms.Label AddNewLabel()
{
System.Windows.Forms.Label lbl = new System.Windows.Forms.Label();
this.Controls.Add(lbl);
lbl.Top = lblCounter * 28;
lbl.Left = 15;
lbl.Text = "Range" + lblCounter;
lblCounter = lblCounter + 1;
return (lbl);
}