I have a method making a (new) lblArray of 35 labels, but the labels on the array need to reset at the push of a button.
So i’ve put the same method in the button1_onclick, but then it just makes a new array underneath the previous one..
Could you guys push me in the right direction please?
Thanks in advance!
David
Some code:
public void CreateLableArray() {
LblArray = new Label[5, 7];
int xpos = 0;
int ypos = 0;
for (int x= 0; x< 5; x++) {
for (int y= 0; y< 7; y++) {
LblArray[x, y] = new Label();
LblArray[x, y].Left = xpos;
LblArray[x, y].Top = ypos;
LblArray[x, y].Width = 50;
LblArray[x, y].Height = 50;
LblArray[x, y].Text = String.Empty;
LblArray[x, y].Click += lblArray_Click;
LblArray[x, y].BackColor = Color.Aqua;
LblArray[x, y].BorderStyle = BorderStyle.FixedSingle;
pnlPanel.Controls.Add(LblArray[x, y]);
xpos += LblArray[x, y].Width;
}
ypos += LblArray[x, 0].Width;
xpos = 0;
}
}/*CreateLableArray*/
private void EmptyLabels() {
for (int x = 0; x < 5; x++) {
for (int y = 0; y < 7; y++) {
LblArray[x, y].BackColor = Color.Aqua;
}
}
}
It sounds like all you need to change for the labels is their color, so rather than making new labels and going through all of the work of removing the old ones and adding the new ones it will be much easier to just change the color of the existing labels. Since you found out how to change it to another color in the first place I assume you’re capable of doing this, yes? If not, just as so and we can help you with the relevant code snippet.