MDI子窗体可以重复打开多个...我要怎么实现MDI子窗体只能打开1个呢?如果已经打开了,用户再打开就Show出来

解决方案 »

  1.   

    将MDI子窗口定义为MdiParent的成员
    private SubForm subForm= null;
    private void onClick(object sender,EventArgs e){
        if(subForm == null || subForm.IsDisposed) subForm = new SubForm();
        subForm.MdiParent = this;
        subForm.WindowState = FormWindowState.Maximized;
        subForm.Show();
    }
      

  2.   

    循环判断激活的窗体,如果有的话,就show,没有就showdialog
      

  3.   

    foreach (Form frm in this.MdiChildren)
    {  
        if (frm is WorkerList)    
        {  
           frm.WindowState = FormWindowState.Normal;      
           frm.Activate();       
           return;    
        }
    }
    WorkerList wl = new WorkerList();
    wl.MdiParent = this;wl.Show();();网上查的资料 我还没试 能好用
      

  4.   

    最好使用单件模式
    public partial class frmLogin : Form
        {
            private static frmLogin myLogin = null;        protected frmLogin()
            {
                InitializeComponent();
            }
            public static frmLogin GetInstance()
            {
                if (frmLogin.myLogin == null)
                {
                    return new frmLogin();
                }
                return myLogin();
            }
        
        }
      

  5.   

    代码是报错的。。return frmLogin();???????????
      

  6.   

    比如你的新窗体名是“wpzklzcxwind”
    foreach (Form from1 in this.MdiChildren)
    {
        if (from1.Name == "wpzklzcxwind")
        {
             return;
        }
    }
    wpzklzcxwind dp = new wpzklzcxwind();
    dp.MdiParent = this;
    dp.Show();
      

  7.   

    foreach (Form frm in this.MdiChildren)
                {
                    if (frm is XiaoshouJ)
                    {
                        frm.WindowState = FormWindowState.Normal;
                        frm.Activate();
                        return;
                    }            }
                XiaoshouJ xj = new XiaoshouJ();
                xj.MdiParent = this;
                xj.Show();
           好用
      

  8.   

    xiaoshouj 是子窗体 我刚试好用
      

  9.   

    gt2007good:
    我把你代码运行了。。login界面登录后进入到MainFram(MDI主窗体),就显示了子窗体,而且还是可以重复打开!!!!
      

  10.   

    ismezy2002不好意思! 没去看你那段代码了。。
      

  11.   

    mainform是主窗体 在里面有个按钮或其他控件 click单击 事件 中写这个代码 在不好用 你告诉我你是怎么谈出 子窗体的
      

  12.   

    foreach(Form  form in Application.OpenForms)
                {
                    if (form.Name == "frmLogin")
                    {
                        form.Activate();
                        return;
                    }
                }
                frmLogin login = new frmLogin();            login.Show();