简体   繁体   中英

How to close form and open another form in a panel when clicking a button?

I have a code that checks if the child container has an open form. My problem is how to close the current form (open form) and open another form, so that the form will not overlap.

       if (MdiChildren.Count() == 0)
        {
            frmLogin f = new frmLogin();
            f.MdiParent = this;
            f.Show();
        }
        else
        {
            this.Close();
            frm1 f = new frm1();
            f.MdiParent = this;
            f.Show();
        }

From Mdi form, loop through all the childforms and either close or minimize the child forms. Then show the active form as explained below.

foreach(Form frm in this.MdiChildren)
{
    frm.Close();

    // or.. just minimize the child forms
    // frm.WindowState = FormWindowState.Minimized;
}

Form frm1 = new Form();
frm1.MdiParent = this;
frm1.Show();

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM