//-------------------------------------------------------------------------------------
/// <summary>
/// Рекурсивно очищает дочерние контролы с вызовом Parent == null
/// </summary>
/// <param name="ctrl"></param>
public static void ClearChilds(Control ctrl)
{
try
{
ctrl.SuspendLayout();
Stack<Control> st = new Stack<Control>();
foreach(Control c in ctrl.Controls)
st.Push(c);
while(st.Count > 0)
{
Control c = st.Pop();
c.Parent = null;
if(c.Controls.Count > 0)
{
foreach(Control cc in c.Controls)
st.Push(cc);
}
c.Controls.Clear();
}
}
finally
{
ctrl.ResumeLayout();
}
}