Click here to Skip to main content
15,031,219 members
Please Sign up or sign in to vote.
1.00/5 (1 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";

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

childForm.Location = new Point(15, 15);
Updated 9-Feb-21 23:39pm

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:[^],
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[^].

Ramza360 31-Jan-15 10:26am
Yet another good point.. Got my 5.
Sergey Alexandrovich Kryukov 31-Jan-15 12:11pm
Thank you, Ramza.
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
[no name] 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.
[no name] 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.
[no name] 31-Jan-15 10:48am
Ok, seems it was as slip, I will take back my bad vote ;)
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;

Hope it helps you.....
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.


following links may help you
Form1 childForm = new Form1();
childForm.MdiParent = this;
childForm.Dock = DockStyle.Fill;
This post is old but maybe I can help someone with this issue. I don´t know if this solutions worked for you but I had to do something different. I'm using though.

I created a Shared Sub in the Mdi Parent Form with this:
Shared Sub CenterFormToScreen()
End Sub

And then in each of the Mdi Childs I wrote this code calling the Sub:

With this I'm simply updating the Main Form (Parent) to return to the center of the screen each time one of the children are shown.

If your problem wasn´t this, then don't mind me.
CHill60 10-Feb-21 7:26am
The question was about the postiioning of child forms, you're off topic

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