Hey
I have a button that when clicked add some pictureboxes and labels on a panel named "hold"
Now when I change some values and reclick this button I need the old controls to be removed before drawing new ones.
So I added this code at the start of the button when its clicked
foreach (Control c in hold.Controls)
{
hold.Controls.Remove(c);
}
That didnt work so I tried this
for (int i = 0; i < hold.Controls.Count; i++)
{
hold.Controls.RemoveAt(i);
}
That also didnt work, the old labels and pictureboxes sit there on the screen and when the new ones are draw on, it messes up the images.
Funny enough these loops work "kinda" work when I place them after the controls are drawn (at the end of the button click) and removes some of the controls, which is what I expect it to, but why only some? and why not work at start of button click?