Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form1 event loads Form2, need Form2 to be child of Form1's MDI 1

Status
Not open for further replies.

Smitty020

MIS
Jun 1, 2001
152
US
I have a form called Form1. It's parent is MDI1.
There is an event in Form1 that loads a form called Form2.
When this happens, how can I make MDI1 also the parent of new Form2?

-Smitty
 
Try setting the IsMdiContainer property to true in the property page for Form1 in the designer. Then in code when you create Form2, set the MdiParent property equal to your Form1 object reference.

Code:
Form2 frm2 = new Form2();

frm2.MdiParent = this; //Assuming this code is in a member of the Form1 class
frm2.Show();
 
Doesn't work. It says that a form cannot be an MdiParent and a MdiChild at the same time. Plus, I want the original MDI container to be the parent of both of the forms.

Thanks!

-Smitty
 
I missed that. I see what you mean now. I think the standard approach would be to have the parent of Form1 also be the parent of Form2 rather than having Form1 be the parent of Form2.

I guess that MS doesn't support a hierarchy of Mdi forms more than 1 level deep.

The only thing that I could suggest would be to use a tab control to organize the contents of Form2 inside Form1 rather than using a separate form.
 
Yeah, I see what you mean. I was even thinking, and maybe someone could help with this, that if was able to call a method in the MDIForm from Form1 to open Form2. That way, the MDI Parent would be correct and it would at least look as if the Form2 was fired from Form1.

Any ideas on how to accomplish that?
 
This code in Form1 ought to work:

Code:
Form2 frm2 = new Form2();

frm2.MdiParent = this.MdiParent;
frm2.Show();
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top