I have wrote some code to automatically make labels. Now I want to call each label in another void. I gave all the labels a label.Name
, but I can't call them with that. How can I call each label? For example I want this in another void:
label12.BackColor = Color.Blue;
void Test()
{
for (j = 0; j < 20; j++)
{
label = new Label();
label.AutoSize = false;
label.Name = "label" + j.ToString() + i.ToString();
label.TabIndex = 0;
label.Text = "[" + j.ToString() + "," + i.ToString() + "]";
label.Visible = true;
this.Controls.Add(label);
label.Location = new Point(Size.Width / 2 - (5 - i) * 50, Size.Height / 2 - (11 - j) * 30);
label.Size = new Size(50, 30);
label.BackColor = Color.White;
if (i % 2 == 0)
{
label.BackColor = Color.Blue;
}
}
}