Winform 避免打开重复窗体

foreach (Form f in Application.OpenForms)
   {
                if (f.Name == "Form1")
                {
                    if (f.WindowState == FormWindowState.Minimized)
                    {
                        f.WindowState = FormWindowState.Normal;
                    }
                    f.Activate();
                    f.Show();
                    return;
                }
    }

    Form1  f2 =new  Form1();
    f2.Name = " Form1";
    f2.Show();
posted @ 2022-06-13 13:14  码农阿亮  阅读(191)  评论(0编辑  收藏  举报