Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
- How to bring a MDI child form to the front when MDI Parent has some controls in it

I have created a "MDI Parent" form containing a Split Container & Tree View Controls, when i try to open a Form (MDI Child), that form opens behind the Split Container. Could some one please explain how to set this right.

If this is using controls class - MDICLIENT ... how do we now the exact number of the client control which represents the Child Form.
Ex:

in the following code we do not know the value for i

C#
MdiClient mdiClient = null;

               // Get the MdiClient from the parent form.

               for (int i = 0; i < this.Controls.Count; i++)
               {
      // If the form is an MDI container, it will contain an MdiClient control

   // just as it would any other control.

                 mdiClient = this.Controls[i] as MdiClient;
                   if (mdiClient != null)
                   {
                       // The MdiClient control was found.

                     // MessageBox.Show("name "+mdiClient.ToString());

                       //
                       mdiClient.BringToFront();

                       break;
                   }
               }
Posted
Updated 2-Jan-12 7:46am
v2

MDI parent form should not have any controls on it excluding status bar or menu bar etc. MDI children are drawn behind the controls on MDI parent.

Also if this is a new software consider moving to SDI interface since MDI is deprecated actually a long time ago. For new users SDI is more convenient and familiar interface than the MDI which has different kinds of limitations.
 
Share this answer
 
Comments
Anthony Dilshan 2-Jan-12 20:52pm    
Thanks... guess I'll take your advice, in using SDI
Wendelius 3-Jan-12 0:26am    
You're welcome :)
This is problematic because the MDI parent is not designed to host any controls except one. This control (which you can access using raw Windows API) is so called MDI client, it takes the whole client area of the MDI parent and is only designed to host MDI children. I remember that even the problem of drawing some background image on this surface was difficult.

So, here is my advice: stop torturing yourself and scare off your users with this rotten UI design. Even Microsoft does what it takes to discourage it. It is excluded from WPF and probably kept in Forms just for compatibility with legacy. Did you ever see any MDI UI which is at least professional? There is no such thing. You can do much easier to implement design without it, with much better quality. I'll give you an idea on what to do.

Please see:
http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages[^],
Question on using MDI windows in WPF[^],
MDIContainer giving error[^],
How to Create MDI Parent Window in WPF?[^],
How to set child forms maximized, last childform minimized[^].

Good luck,
—SA
 
Share this answer
 
Comments
Anthony Dilshan 2-Jan-12 20:53pm    
Thanks..I've checked the sites...I see why I should not use MDI. Thanks for the advice.
I had this issue too and this is the code I used to handle it.

public partial class frmBeam : Form
{
frmMain FormMain;
frmBeamControl FormBeamControl;

private void frmBeam_Click(object sender, EventArgs e)
{
FormBeamControl = new frmBeamControl();
FormBeamControl.Show();
this.FormBeamControl.TopMost = true;
}

}
 
Share this answer
 
v2
Comments
Richard C Bishop 12-Apr-13 12:37pm    
Please do not post answers to old threads. This one is almost a year and half old.
Load child form inside a panel then add that panel in MDI runtime
and it will work same as you desire...
C#
Form1 frm = new Form1(); // Child form's object
Panel p = new Panel(); // Run time a panel is created
p.Controls.Add(frm); // add child form in panel
this.Controls.Add(p); // 'this' means MDI so, add panel inside MDI
p.BringToFront(); // get panel in front or you can focus a control of child form
p.show(); // finally show form in MDI

Happy Coding!
:)
 
Share this answer
 
Comments
Richard C Bishop 12-Apr-13 13:59pm    
Did you realize this thread is over a year old?
Aarti Meswania 12-Apr-13 14:03pm    
right but it was listed in active questions in first page
so, I didn't notice the time of post
Richard C Bishop 12-Apr-13 14:05pm    
I know, it happens. Done it myself before. I always check the dates now.
Aarti Meswania 12-Apr-13 14:06pm    
:)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900