/// <summary> /// Main Show routine /// </summary> static private DialogResult Show(Form parent, Form child, FormDepth depth, bool isModal, bool isVirtual) { DialogResult result = DialogResult.None; FormHolder holder = CreateFormHolder(child, depth, isModal); AddForm(holder); try { holder.mForm.StartPosition = FormStartPosition.CenterParent; if (isVirtual) { // this is a virtually modal form if (parent != null) { parent.Invoke(new DisableParentDelegate(DisableParent), new object[] { parent }); } if (!isModal) { holder.mForm.Show(); } } else { if (isModal) { //this is a pure modal form result = holder.mForm.ShowDialog(parent); Close(holder.mForm); } else { // this is not modal nor is it virtually modal, so just show it modeless holder.mForm.Show(); } } } // Ignore any ThreadAbortExceptions (but keep this code here so we can observe them) catch (ThreadAbortException ex) { Debug.WriteLine(ex.ToString()); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); // If we've caught, re-enable our parent (just in case) if (parent != null) { //Debug.WriteLine(parent.Name + " - (Exception)BackForm ReEnabled", "Show"); parent.Enabled = true; } } return(result); }
/// <summary> /// Bring the highest form to the top of our window /// </summary> static private Form GetTopmostForm(FormDepth zone) { // I assume the latest node in our sorted list is the highest because it is a sorted(by depth) list for (int z = (int)zone; z >= 0; z--) { if (mForms[z].Count > 0) { // I assume the latest node in our sorted list is the highest because it is a sorted(by depth) list FormHolder holder = mForms[z].GetByIndex(mForms[z].Count - 1) as FormHolder; return(holder.mForm); } } return(null); }
/// <summary> /// Create a formHolder object with the correct depth and event handlers /// </summary> /// <param name="form"></param> /// <param name="depth"></param> /// <returns></returns> static private FormHolder CreateFormHolder(Form form, FormDepth depth, bool isModal) { // Create our handle FormHolder holder = new FormHolder(); // Assign it our vars holder.mForm = form; holder.mDepthZone = depth; holder.mModal = isModal; // Determine its depth base on its zone switch (depth) { case FormDepth.BACK: holder.mDepth = mCurrentBack++; break; case FormDepth.MID: holder.mDepth = mCurrentMid++; break; case FormDepth.TOP: holder.mDepth = mCurrentTop++; break; } // Mark down in our list that this holder goes with this form AddHolderMap(form, holder); // Override the forms activated event handle form.Activated += new EventHandler(form_Activated); form.Closed += new EventHandler(form_Closed); // Return the new object return(holder); }
static public void VirtualModal(Form parent, Form form, FormDepth depth) { Show(parent, form, depth, true, true); }
static public DialogResult ShowModal(Form parent, Form form, FormDepth depth) { return(Show(parent, form, depth, true, false)); }
/// <summary> /// Show functions /// </summary> /// <param name="form"></param> /// <param name="depth"></param> static public void Show(Form form, FormDepth depth) { Show(null, form, depth, false, false); }
/// <summary> /// Assign the initial parent form /// </summary> /// <param name="form"></param> /// <param name="depth"></param> static public void InitParent(Form form, FormDepth depth) { FormHolder holder = CreateFormHolder(form, depth, false); AddForm(holder); }