winform Application.OpenForms 判断打开的窗体数量

List<string> openFrom = new List<string>();
if (Application.OpenForms.Count > 2)
{
string result = string.Empty;
for (int i = 0; i < Application.OpenForms.Count; i++)
{
openFrom.Add(Application.OpenForms[i].GetType().ToString());
}
openFrom.Remove("system.WindowForm1");
openFrom.Remove("system.WindowForm2");
for (int i = 0; i < openFrom.Count; i++)
{
result += openFrom[i] + " $$ ";
}
if(openFrom.Count > 0)
{
return "请先关闭打开的窗体" + result;
}
}

posted @ 2024-01-18 12:30  二零一七  阅读(47)  评论(0编辑  收藏  举报