C# Winform 单例的Form窗体

using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public static void ShowUI()
        {
            if (singleton == null || singleton.IsDisposed)
            {
                singleton = new Form1();
            }
            else
            {
                if (singleton.WindowState == FormWindowState.Minimized)
                {
                    singleton.WindowState = FormWindowState.Normal;
                }
                singleton.Activate();
            }
            if (!singleton.Visible)
            {
                singleton.Show();
            }
        }
        private static Form1 singleton;
        private Form1()
        {
            InitializeComponent();
        }
    }
}

 

posted on 2013-06-07 19:09  yao2yao4  阅读(468)  评论(0编辑  收藏  举报

导航