Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 849
Saeid Yazdani Avatar asked Nov 01 '11 13:11

Saeid Yazdani


2 Answers

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.

like image 159
Gabe Thorns Avatar answered Oct 06 '22 15:10

Gabe Thorns


Well, not to argue with the "solution" that was listed... but if I'm understanding the request correctly and trying the above solution didnt work i would do the following....

Form2 f2 = new Form2();
        f2.MdiParent = MDIParent1.ActiveForm;
        f2.Show();
like image 44
user1762132 Avatar answered Oct 06 '22 15:10

user1762132