c# 打开MDI窗口,防止打开多个MDI窗口

public static void openChildrenWindow(System.Windows.Forms.Form parentWindow, System.Windows.Forms.Form childrenWindow)
        {
            foreach (System.Windows.Forms.Form ff in parentWindow.MdiChildren)
            {
                //如果子窗体存在,激活子窗体
                if (ff.Name == childrenWindow.Name)
                {
                    ff.Activate();
                    ff.Size = ff.Parent.Size;
                    ff.WindowState = System.Windows.Forms.FormWindowState.Maximized;
                    //((frmMain)parentWindow).s slblOperate.Text = ff.Text;

                    return;
                }
            }
            parentWindow.IsMdiContainer = true;
            childrenWindow.MdiParent = parentWindow;
            childrenWindow.WindowState = System.Windows.Forms.FormWindowState.Maximized;
            //parentWindow.ActiveMdiChild = childrenWindow;
            childrenWindow.Show();
        }

调用:

    openChildrenWindow(this, new Form2());  //form2需要打开的窗体  

posted @ 2008-10-04 14:08  novel  阅读(674)  评论(0编辑  收藏  举报