C# 设置MDI窗体

1。设置父窗体

在待设父窗体的【属性】中,将IsMdiContainer属性设置为True即可。

2、判断父窗口是否已经打开

C# 设置MDI窗体
   /// <summary>
        /// 判断父窗口是否已经打开
        /// </summary>
        /// <param name="formParent"></param>
        /// <param name="childName"></param>
        /// <returns></returns>
        private bool HaveOpened(Form formParent, string childName)
        {
            //查看窗口是否已经被打开
            bool bReturn = true;
            for (int i = 0; i < formParent.MdiChildren.Length; i++)
            {
                if (formParent.MdiChildren[i].Name == childName)
                {
                    formParent.MdiChildren[i].BringToFront();
                    bReturn = false;
                    break;
                }
            }
            return bReturn;
        }
View Code

 

3、执行打开嵌入窗口操作按钮

C# 设置MDI窗体
        /// <summary>
        /// ‘操作打开菜单’
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void barButGet_ItemClick(object sender, ItemClickEventArgs e)
        {
            FormXG formXG = new FormXG();
            if (HaveOpened(FormMain.ActiveForm, "嵌入窗口标题"))
            {
                formXG.MdiParent = FormMain.ActiveForm;
                formXG.WindowState = FormWindowState.Normal;
                formXG.MdiParent = this;
                formXG.Show();
            }
        }
View Code

 

C# 设置MDI窗体

上一篇:SQL 2008R2 日期转换


下一篇:AcWing 146. 序列