单例模式

《大话设计模式》书中的方法

 public partial class Form1 : Form
    {
        private void toolStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
             Form2.GetSingleForm2().Show();
        }
    }

    public partial class Form2 : Form
    {
        private static Form2 _singleForm = null;
        private Form2()
        {
            InitializeComponent();
        }
        public static  Form2 GetSingleForm2()
        {
            if (_singleForm == null || _singleForm.IsDisposed)
            {
                _singleForm = new Form2();
                _singleForm.MdiParent = Form1.ActiveForm;
            }
            return _singleForm;
            
        }
    }

 

posted @ 2013-06-14 18:04  瓜王  阅读(145)  评论(0编辑  收藏  举报