How can I remove all labels where Name
starts with "ToClear"?
I tried this code, but it clears them in two clicks (if there are 26 labels it only removes 13 per click)
private void ClearLabel()
{
foreach (var _object in this.Controls)
{
Console.WriteLine(((Label)_object).Name);
if (_object is Label && ((Label)_object).Name.StartsWith("ToClear"))
{
this.Controls.Remove(this.Controls[((Label)_object).Name]);
}
}
}