Hi
I am trying to create 400 labels to fill my control panel for a minesweeper project. I am using a for loop to create it but seem to be going wrong. Here is what i have so far.
Also is there any way I can add this to the designer.cs file in order that when the form loads all 400 labels have populated the control panel.
Any assistance would be appreciated.
Thanks
I am trying to create 400 labels to fill my control panel for a minesweeper project. I am using a for loop to create it but seem to be going wrong. Here is what i have so far.
C#:
int distance = 10;
int labcounter = 0;
private void GreyPanel_Paint(object sender, PaintEventArgs e)
{
new List<Label> { label1, label2,};
while ( labcounter <= 400)
{
Label lbl = new Label();
this.Controls.Add(lbl);
lbl.BackColor = System.Drawing.Color.SkyBlue;
lbl.Location = new System.Drawing.Point(10 + distance, 10 + distance);
lbl.Name = "label1" + labcounter;
lbl.Size = new System.Drawing.Size(20, 20);
lbl.TabIndex = 0;
labcounter = labcounter + 1;
Also is there any way I can add this to the designer.cs file in order that when the form loads all 400 labels have populated the control panel.
Any assistance would be appreciated.
Thanks
Last edited by a moderator: