コード例 #1
0
        /// <summary>
        /// Load Child form in MDI parent
        /// </summary>
        /// <param name="parentForm">Name of parent form</param>
        /// <param name="childlForm">Name of child form</param>
        /// <param name="nestedLevel">Nesting level of the child form</param>
        /// <param name="buttonName">Button that activate child form.</param>
        public static void LoadChildForm(Form parentForm, Form childlForm, ChildNastedLevel nestedLevel, GradientButton buttonName)
        {
            switch (nestedLevel)
            {
            case ChildNastedLevel.Nasted:
            {
                //Deactivate buttonName
                DeactivateButton(parentForm, buttonName);

                childlForm.MdiParent = parentForm;
                childlForm.Show();

                CloseAllOpenChildtrenExceptLoadingChild(parentForm, childlForm, ChildNastedLevel.Nasted);
                break;
            }

            case ChildNastedLevel.NastedNasted:
            {
                //Deactivate buttonName
                DeactivateButton(parentForm, buttonName);

                childlForm.MdiParent = parentForm.MdiParent;
                childlForm.TopLevel  = false;
                childlForm.Show();

                CloseAllOpenChildtrenExceptLoadingChild(parentForm, childlForm, ChildNastedLevel.NastedNasted);
                break;
            }

            case ChildNastedLevel.NastedNastedNasted:
            {
                DeactivateButton(parentForm, buttonName);

                childlForm.TopLevel = false;
                //parentForm.MdiParent.Controls.Add(childlForm);

                foreach (Control control in parentForm.MdiParent.Controls)
                {
                    if (control is Form)
                    {
                        if (!parentForm.MdiParent.Controls.Contains(childlForm))
                        {
                            parentForm.MdiParent.Controls.Add(childlForm);
                        }
                    }
                }
                childlForm.Parent  = parentForm.MdiParent;
                childlForm.TopMost = true;
                childlForm.Show();


                CloseAllOpenChildtrenExceptLoadingChild(parentForm, childlForm, ChildNastedLevel.NastedNastedNasted);
                break;
            }
            }
        }
コード例 #2
0
        private static void CloseAllOpenChildtrenExceptLoadingChild(Form parentForm, Form childlForm, ChildNastedLevel nestedLevel)
        {
            switch (nestedLevel)
            {
            case ChildNastedLevel.Nasted:
            {
                foreach (Form form in parentForm.MdiChildren)
                {
                    if (form.GetType() != childlForm.GetType() && form != null)
                    {
                        //form.Hide();
                        form.Close();
                    }
                }
                foreach (Control form in parentForm.Controls)
                {
                    if (form is Form)
                    {
                        (form as Form).Close();
                    }
                }
                break;
            }

            case ChildNastedLevel.NastedNasted:
            case ChildNastedLevel.NastedNastedNasted:
            {
                foreach (Control form in parentForm.MdiParent.Controls)
                {
                    if (form is Form)
                    {
                        if (form.GetType() != childlForm.GetType() && form != null)
                        {
                            //form.Hide();
                            (form as Form).Close();
                        }
                    }
                }
                break;
            }
            }
        }