Child controls have the Parent property. If you remove the parent, Windows Forms will automatically call Dispose () for the children. This is one of the reasons you will never have to explicitly call Dispose () on your child controls when you close the form.
, , , this.Controls.Add(). WF , . :
private void button1_Click(object sender, EventArgs e) {
int nextTab = 0;
foreach (Control ctl in this.Controls) nextTab = Math.Max(nextTab, ctl.TabIndex);
Point offset = groupBox1.Location;
for (int ix = groupBox1.Controls.Count - 1; ix >= 0; --ix) {
Control ctl = groupBox1.Controls[ix];
ctl.Location = new Point(ctl.Left + offset.X, ctl.Top + offset.Y);
ctl.TabIndex += ++nextTab;
this.Controls.Add(ctl);
}
groupBox1.Dispose();
groupBox1 = null;
}