Reputation: 14142
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
?
Upvotes: 13
Views: 57820
Reputation: 1
I had the same problem and tried all different solutions. Finally the one that worked for me was:
Dim ChildForm As New AddingText("")
' Make it a child of this MDI form before showing it.
ChildForm.MdiParent = MDIParent1
ChildForm.Dock = DockStyle.Fill
MDIParent1.m_ChildFormNumber += 1
ChildForm.Text = "Client Existent" & MDIParent1.m_ChildFormNumber
ChildForm.Show()
the hiccup is that could not be used in conjunction with ShowDialog(), but i can live with it.
Upvotes: 0
Reputation: 1
Let us suppose that the second form is frm2.Then, the code in form frm1 to create a new form frm2 in MDI parent form will be: create new object then again retrived data mdiparent forms solved freeze dispose form
Dim dru as New frm2 '// another form call
dru = New frm2
dru.mdiparent = frm1 '// main forms
dru.show()
Upvotes: 0
Reputation: 528
Let us suppose that the second form is f2.Then, the code in form f1 to create a new form f2 in MDI parent form will be:
Form2 f2 = new Form2;
f2.MdiParent = this.MdiParent;
f2.Show();
Upvotes: 12
Reputation: 315
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();
Upvotes: 5
Reputation: 1426
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.
Upvotes: 42