我的程序目前设置为仅在原始控件下方添加一行控件。我怎样才能做到这一点,以便用户可以添加任意多的控件行?
private void surfaceAddButton_Click(object sender, EventArgs e)
{
//Adds new set of controls on button click
for (int i = 1; i < 2; i++)
{
ComboBox surfaceCombo2 = new ComboBox();
TextBox sideWallsText2 = new TextBox();
TextBox backWallsText2 = new TextBox();
TextBox floorText2 = new TextBox();
Label newLabel = new Label();
Label newLabel2 = new Label();
Label newLabel3 = new Label();
Absorption_Coefficients alpha = new Absorption_Coefficients(); //Adds surfaces to combobox
List<string> materialslist = alpha.listLoad();
materialslist.Sort();
surfaceCombo2.Items.AddRange(materialslist.ToArray());
surfaceCombo2.DropDownStyle = ComboBoxStyle.DropDownList;
//Sets locations and sizes of new row of options, then displays them
surfaceCombo2.Location = new Point(1, 150 * i + 30);
sideWallsText2.Location = new Point(393, 153 * i + 30);
backWallsText2.Location = new Point(561, 153 * i + 30);
floorText2.Location = new Point(711, 153 * i + 30);
newLabel.Location = new Point(321, 158 * i + 30);
newLabel2.Location = new Point(439, 158 * i + 30);
newLabel3.Location = new Point(609, 158 * i + 30);
surfaceCombo2.Width = 322;
sideWallsText2.Width = 43;
backWallsText2.Width = 43;
floorText2.Width = 43;
newLabel.Text = "Side Walls, ft²";
newLabel2.Width = 120;
newLabel2.Text = "Back/or Front Walls, ft²";
newLabel3.Text = "Floor/or Ceiling, ft²";
this.Controls.Add(surfaceCombo2);
this.Controls.Add(sideWallsText2);
this.Controls.Add(backWallsText2);
this.Controls.Add(floorText2);
this.Controls.Add(newLabel);
this.Controls.Add(newLabel2);
this.Controls.Add(newLabel3);
this.Size = new Size(769, 209 * i + 30); //Increases form to accomodate new controls
}
}
这是仅添加了一个表面的形式。我想这样做,所以每次用户单击 +Surface 时,下面都会有一个新行。