我做了一个主界面(from1)设置IsMdiContainer设为True,点击Button显示副页面(from2),将from2显示在from1里面,from1 f = new from1();
f.MdiParent = this;
f.show();完成,我想让from2在from1里只能打开一个,如何实现???

解决方案 »

  1.   

    使用单件模式:
    Form2:
    private static from2 _instance;
    public static from2 Instance()
    {
        if (_instance == null)
            _instance = new from2();
        else
            _instance.Activate();
        return _instance;
    }
    Form1:
    Form2 frm = Form2.Instance();
    frm .MdiParent = this;
    frm .show();
      

  2.   

    那from2的代码应该添加到哪边呢???
      

  3.   

    就直接添加到Form2的Class文件里面就行了
    为了防止混淆,最好好Form2的构造函数设成私有的