天天看点

判断WinForm窗体是否已经打开

判断WinForm窗体是否已经打开

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace IceInk
{
    /// <summary>
    /// //基于WinForm窗体的帮助类
    /// </summary>
    public class EkWinFormHelper
    {

        /// <summary>
        /// 判断窗体是否打开
        /// </summary>
        /// <typeparam name="T">窗体类型</typeparam>
        /// <returns></returns>
        public static bool CheckIsOpenForm<T>() where T : Form
        {
            Type wormType = typeof(T);

            foreach (Form frm in Application.OpenForms)
            {
                if (frm.Name.Equals(wormType.Name))
                {
                    return true;
                }
            }

            return false;
        }
    }
}