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();

        }

    }

}

 

你可能感兴趣的:(WinForm)