/// <summary> /// Closes all child windows of this MDI window /// </summary> private void CloseChildWindows() { while (SubWindows.Count > 0) { Form window = (Form)SubWindows.First(); EnsureIsClosed(window); } }
/// <summary> /// Adds a child window to this parent MDI /// </summary> /// <param name="window"></param> /// <returns></returns> public void AddChildWindow(Form window) { if (window != null) { window.MdiParent = this; window.Show(); window.Activate(); if (window is IBaseForm) { SubWindows.Add((IBaseForm)window); } ActivateMdiChild(window); } }
/// <summary> /// Ensures that a window is closed /// </summary> /// <param name="window"></param> /// <returns></returns> private void EnsureIsClosed(Form window) { if (window != null) { try { window.Close(); window.MdiParent = null; if (window is IBaseForm) { SubWindows.Remove((IBaseForm)window); } RemoveOwnedForm(window); } catch (Exception) { } } }