Connecting Tech Pros Worldwide Help | Site Map

Multiple mdi Children

Newbie
 
Join Date: Mar 2009
Location: Moldova, Chisinau
Posts: 4
#1: Aug 18 '09
I have a main window (form) wich is an mdi container.
i can open one form which mdi parent is this main window like this:

NewDistribution distr = new NewDistribution();
distr.MdiParent = this;
distr.Show();

in this New Distribution i have a new button wich opens another form... how do i set the second form to be opened in the main window's mdi container?
cause it is opening like a separate form...
Attached Thumbnails
mdi.jpg  
Expert
 
Join Date: Jun 2008
Location: Pretoria, South Africa
Posts: 410
#2: Aug 18 '09

re: Multiple mdi Children


Hi

You need to do this in the event handler of the button which will open the second form.
You simply create a new instance of the form you wish to show and set its MdiParent parent property equal to your main form and call the show() method of the new form. See below for an example:

Expand|Select|Wrap|Line Numbers
  1. //MainWindowName is the name of your main MDI parent form
  2. Form newMDIChildForm = new Form();
  3. newMDIChildForm.MdiParent = Application.OpenForms["MainWindowName"];
  4. newMDIChildForm.Show();
Hope this helps
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,739
#3: Aug 18 '09

re: Multiple mdi Children


The thumbnail is tiny and of no real value. Can you post a full size image?

Do I understand your question correctly?
You have a parent form that opens a child form.
You have a button on the child.
You want the child's button to cause another form to open, as another child of the main - not as a child of the child.

Does that sound right?
Newbie
 
Join Date: Mar 2009
Location: Moldova, Chisinau
Posts: 4
#4: Aug 19 '09

re: Multiple mdi Children


Yes, it helped, Thank You,
meanwhile i found a provisory solution for me...

Expand|Select|Wrap|Line Numbers
  1. Form newMDIChildForm = new Form();
  2. newMDIChildForm.MdiParent = this.MdiParent;
  3. newMDIChildForm.Show();
Quote:

Originally Posted by cloud255 View Post


Hi

You need to do this in the event handler of the button which will open the second form.
You simply create a new instance of the form you wish to show and set its MdiParent parent property equal to your main form and call the show() method of the new form. See below for an example:

Expand|Select|Wrap|Line Numbers
  1. //MainWindowName is the name of your main MDI parent form
  2. Form newMDIChildForm = new Form();
  3. newMDIChildForm.MdiParent = Application.OpenForms["MainWindowName"];
  4. newMDIChildForm.Show();
Hope this helps

Reply

Tags
c sharp, child, children, mdi, parent