简体   繁体   中英

C# - Opening mdi child form from another mdi child form's button

Can I actually open another mdi child form using the first mdi child form's button?

// Form1 is MdiParent
// Form2 is MdiChild1
// Form3 is MdiChild2

// Form2's code

private void button1_Click(Object sender, EventArgs e)
{
    Form1 parentForm = new Form1();
    Form3 childForm2 = new Form3();
    childForm2.MdiParent = parentForm;
    childForm2.Show();
}

My problem is when I clicked the button, it didn't showed up

It's appens because you are not showing the Form1 . If you want show mdi child form do this:

Form1 parentForm = new Form1();
Form3 childForm2 = new Form3();
childForm2.MdiParent = parentForm;
parentForm.Show();
childForm2.Show();

If Form1 is your current form and you want display the mdi child form into this form do this:

Form3 childForm2 = new Form3();
childForm2.MdiParent = this;
childForm2.Show();

PS I suggest you to don't use the default name because if you will have much usercontrol it will be mad to discover the correct control

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