C# 通用单例窗体类

    /// <summary>
    /// 通用的单例制作器
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class UniversalSingletonGeneator<T> where T : Form,new()
    {
        private static T t = null;
        public static T CreateSingleton()
        {
            if (t == null || t.IsDisposed)
            {
                t = new T();
            }
            t.WindowState = FormWindowState.Normal;
            t.Activate();
            return t;
        }
    }

   // 测试代码
    var pFrm = UniversalSingletonGeneator<Form1>.CreateSingleton();
    pFrm.Show();
posted @ 2018-07-06 10:06 帆帆帆 阅读(...) 评论(...) 编辑 收藏