Skip to content

Child MDI force Parent MDI to open new child.

Jamie Brunton

Asked Oct 18, 2010, 9:08 AM EDT1 answer
Share
LinkedInX
Is there a way that a child form in a MDIContainer can get the parent to open a new child?

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    I have a parent Form named Form1, and 2 child forms called Child1 and Child2. In the parent form you need to do something like the following.
    public partial class Form1 : Form
    {
    public Form initForm = new Child1();
    public Form nextChildForm = new Child2();
    private void Form1_Load(object sender, EventArgs e)
    {
    initForm.MdiParent = this;
    initForm.Show();
    nextChildForm.MdiParent = this;
    }
    }
     
    In the Child1 form, i have a button to display the other child form, here is the code to perform that.
    private void button1_Click(object sender, EventArgs e)
    {
    Form1 parent = (Form1)this.MdiParent;   // Form1 needs to be the name of the parent form
    parent.nextChildForm.Show();               // can perform on public items
    }
    0