Search code examples
c#winformsmdichildmdiparent

Opening a child form from another child form and set MDI to parent form - how to do?


I have a MDI form. within this MDI form I can open some child forms using:

This is within MainForm

Form1 f1 = new Form1;
f1.MdiParent = this; //this refers to MainForm (parent)
f1.Show();

This works as expected!

But Now, while I am in the child form (Form1 -> f1) I want to open another form as a child for MainForm but when I use this keyword it will reffer to f1. How can I open the new form within f1 and set its MdiParent to MainForm ?


Solution

  • Try assigning the parent form of your first child from:

    Form2 f2 = new Form2;
    f2.MdiParent = this.ParentForm; //this refers to f1's parent, the MainForm
    f2.Show();
    

    Hope this helps.