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(); } }); }
protected virtual void CloseAllDisplays() { foreach (IMdiChildForm childForm in MdiChildren.ToList()) { ((Form)childForm).Close(); MdiChildren.Remove(childForm); ((Form)Parent).Controls.Remove((Form)childForm); childForm.Dispose(); } }
// mdi child event handlers (child window->controller) private void MdiChild_FormClosing(object sender, FormClosingEventArgs e) { MdiChildren.Remove((IMdiChildForm)sender); }