C# WinForm关闭所有子窗口的方法

// 遍历并关闭所有子窗口
FormCollection childCollection = Application.OpenForms;
for (int i = childCollection.Count; i-- > 0;)
{
if (childCollection[i].Name != “父窗口标题”) childCollection[i].Close();
}
// 或者也可以这样写:
FormCollection childCollection = Application.OpenForms;
for (int i = childCollection.Count; i-- > 0;)
{
if (childCollection[i].Name != this.Title) childCollection[i].Close();
}

你可能感兴趣的:(C#,c#)