I have a form containing two buttons.
The first one adds some GroupBoxes
to the form, with this handler:
private void btnAdd_Click(object sender, EventArgs e)
{
GroupBox[] g_arr = new GroupBox[2];
for (int i = 0; i < g_arr.Length; i++)
{
g_arr[i] = new GroupBox();
g_arr[i].Location = new Point(280, (i*-50) + 300);
g_arr[i].Size = new Size(337, 380);
this.Controls.Add(g_arr[i]);
}
}
The second one is supposed to remove every GroupBoxes
inside the form, but not all of them disappear when it's clicked:
private void btnDelete_Click(object sender, EventArgs e)
{
foreach (Control c in this.Controls)
{
if (c is GroupBox)
{
this.Controls.Remove(c);
}
}
}
Why doesn't my remove button manage to remove every GroupBox
?