protected virtual async Task CloseChildWindowAsync(IWin32Window windowHandle) { await Task.Run(() => { IMdiChildForm mdiChildToClose = null; foreach (IMdiChildForm mdiChild in MdiChildren) { if (mdiChild.WindowHandle == windowHandle) { mdiChildToClose = mdiChild; break; } } if (mdiChildToClose != null) { MdiChildren.Remove(mdiChildToClose); mdiChildToClose.CloseWindow(); mdiChildToClose.Dispose(); } }); }
/// <summary> /// 如果窗体已经打开激活即可. /// </summary> /// <param name="mdiParent">主窗体对象引用</param> /// <param name="formTypeName">子窗体的命名空间全名</param> /// <returns></returns> public static Form ActiveChildForm(Form mdiParent, string formTypeName) { for (int x = 0; x < mdiParent.MdiChildren.Length; x++) { string ss = mdiParent.MdiChildren[x].GetType().ToString().ToUpper(); //名字空间 if (ss == formTypeName.ToUpper()) //找到字窗体 { IMdiChildForm child = mdiParent.MdiChildren[x] as IMdiChildForm; if (child.AllowMultiInstatnce) { continue; //跳过窗体副本 } mdiParent.MdiChildren[x].Activate(); return(mdiParent.MdiChildren[x]); } } return(null); }