Click here to Skip to main content
14,357,676 members
Rate this:
Please Sign up or sign in to vote.
See more:
Every time I open a new form through a MDI parent regardless it is same or different form, it changes its location. I assume that it must be a default behavior, But I would like to open all the form at SAME LOCATION,

If user opens multiple forms through a MDI parent, recently opened forms will go out of the screen and user have to drag them manually at the center(this would be annoying for them.)

Below is the code for opening child form through MDI parent

frmCreateClient childForm = new frmCreateClient();
            childForm.MdiParent = this;
            childForm.Text = "New Client";
            childForm.Show();


I tried to add location in the above code as below, but it didn't work

childForm.Location = new Point(15, 15);
Posted
Updated 14-Apr-13 7:40am
v2
Rate this:
Please Sign up or sign in to vote.

Solution 3

Here is the idea: who needs MDI, ever? Why torturing yourself and scaring off your users?
Do yourself a great favor: do not use MDI at all. You can do much easier to implement design without it, with much better quality. MDI is highly discouraged even by Microsoft, in fact, Microsoft dropped it out of WPF and will hardly support it. More importantly, you will scare off all your users if you use MDI. Just don't. Please see:
http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages[^],
How to Create MDI Parent Window in WPF?[^].

I can explain what to do instead. Please see my past answers:
How to Create MDI Parent Window in WPF? [Solution 2],
Question on using MDI windows in WPF[^],
MDIContainer giving error[^],
How to set child forms maximized, last childform minimized[^].

—SA
   
Comments
Ramza360 31-Jan-15 10:26am
   
Yet another good point.. Got my 5.
Sergey Alexandrovich Kryukov 31-Jan-15 12:11pm
   
Thank you, Ramza.
—SA
Rate this:
Please Sign up or sign in to vote.

Solution 6

You are close with the location. However to ensure the form is placed where you want using the Location property, you must first set the StartPosition to Manual.

Setting the StartPosition to manual will allow the Location property to actually work correctly.

frmCreateClient childForm = new frmCreateClient();
childForm.MdiParent = this;
childForm.Text = "New Client";
childForm.StartPosition = FormStartPosition.Manual;
childForm.Location = new Point(15,15); // Always opens the forms at 15,15
childForm.Show();
   
Comments
0x01AA 31-Jan-15 10:32am
   
You are far away....:(
Ramza360 31-Jan-15 10:37am
   
This is a correct solution if you want to set the child to the same "specified" point (e.g. using Location), otherwise you can use one of the other FormStartPositions. Perhaps you should test this (go ahead try it). It does exactly what he needs.
0x01AA 31-Jan-15 10:41am
   
But you are a "Little" bit late the question is dated on 14-Apr-13....who cares.
Ramza360 31-Jan-15 10:42am
   
HAHAHAHAHAHA So true... perhaps i should pay attention to that.
0x01AA 31-Jan-15 10:48am
   
Ok, seems it was as slip, I will take back my bad vote ;)
Rate this:
Please Sign up or sign in to vote.

Solution 2

You need to set startup position of your childs to center to parent and all forms would open at same location. consider the following code for same.

frmCreateClient childForm = new frmCreateClient();
          childForm.MdiParent = this;
          childForm.Text = "New Client";
          childForm.StartPosition = FormStartPosition.CenterParent;
          childForm.Show();


Hope it helps you.....
   
Comments
Noel Macara 20-Sep-18 5:40am
   
Thank you for this Raj. I was tearing my hair out by trying to accomplish the same thing with childForm.Location = this.Location (where this represented the Parent form). That does not do what the job that your snippet does - and which I wanted.

Cheers,

Noel
Rate this:
Please Sign up or sign in to vote.

Solution 1

following links may help you
http://www.codeproject.com/Articles/3553/Introduction-to-MDI-Forms-with-C

http://www.codeproject.com/Articles/7571/Creating-MDI-application-using-C-Walkthrough
   
Rate this:
Please Sign up or sign in to vote.

Solution 4

Form1 childForm = new Form1();
childForm.MdiParent = this;
childForm.Dock = DockStyle.Fill;
childForm.Show();
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100