C# winform判断窗体是否已打开

frm_Set frm_Set;
        /// <summary>
        /// 开始检测
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            if (frm_Set==null) //如果子窗体为空则创造实例 并显示
            {
                frm_Set= new frm_Set();
                frm_Set.StartPosition = FormStartPosition.CenterScreen;//子窗体居中显示
                frm_Set.Show();
            }
            else
            {
                if (frm_Set.IsDisposed) //若子窗体关闭 则打开新子窗体 并显示
                {
                    frm_Set= new Form1();
                    frm_Set.StartPosition = FormStartPosition.CenterScreen;//子窗体居中显示
                    frm_Set.Show();
                }
                else
                {
                    frm_Set.Activate(); //使子窗体获得焦点
                }
            }
        }

    原文作者:天锋
    原文地址: https://blog.csdn.net/yugui/article/details/118381357
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞