I am developing a windows application where I want to create some controls dynamically inside a loop. The code I am trying is
private Label newLabel = new Label();
private int txtBoxStartPosition = 100;
private int txtBoxStartPositionV = 25;
for (int i = 0; i < 7; i++)
{
newLabel.Location = new System.Drawing.Point(txtBoxStartPosition, txtBoxStartPositionV);
newLabel.Size = new System.Drawing.Size(70, 40);
newLabel.Text = i.ToString();
panel1.Controls.Add(newLabel);
txtBoxStartPositionV += 30;
}
This code is generating only one Label with text 7 but I want to create 8 Lables with their respective texts, how can I do this?