1。设置父窗体
在待设父窗体的【属性】中,将IsMdiContainer属性设置为True即可。
2、判断父窗口是否已经打开
/// <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; }
3、执行打开嵌入窗口操作按钮
/// <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(); } }