I was intending to have this create as many textboxes as the value of numericUpDown1, and I'm going to make some tweaks so that it also deletes textboxes when the value is lowered, but it is not functioning at all. I'm not really sure why this is happening.
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
var numVal = numericUpDown1.Value;
int count = 2;
int y = 86;
for (int i = 0; i < numVal; i++)
{
//Create the dynamic TextBox.
TextBox text1 = new TextBox();
y += 20;
text1.Location = new Point(719, y);
text1.Name = "gearText_" + count;
count += 1;
}
}
Dictionary<int, TextBox>. -- Note that, to remove a Control, you must dispose of it. To add it, you should add one or more to a collection, but not repeat the same loop each time the counter is increased (thus, you should probably store the previous value and use the difference).