Positioning MDI form...

lidds

Junior Contributor
Joined
Nov 9, 2004
Messages
210
I'm trying to figure out how to position a MDI form (frmChild) in the centre of it's parent form (frmMain). Could anyone please provide me with some sample code if possible in vb.net.

Cheers

Simon
 
I believe you only have to set the startposition property of the child form to CenterScreen. If it's not CenterScreen it's CenterParent... :eek:

Alex :p
 
I came across this posting after searching for "positioning mdi" in Google because I couldn't figure out how to position an MDI child form, so forgive me if I'm taking over this thread for this purpose. Just wanting to help anyone else who is trying to figure this out on their own and might have come across this thread.

Okay. Generally speaking, you might have been trying to use the child form's .Left, .Top, or .Location properties in an attempt to position the form. However, as you would have seen by now, this doesn't appear to work. When following the link kindly provided by PlausiblyDamp you would have noticed some VB code written by dynamic_sysop which uses a cast to the .MdiParent property of the child form before setting the form's location. I've confirmed that this works, but if you're using C# (as I am), then similar code is as follows (assuming you're placing this code in the _Load method of the MDI child form, the child form has already been shown, and your MDI parent form is named "MDIParent"):

this.MdiParent = (MDIParent)this.MdiParent;
this.Location = new Point(300, 300);

Of course, follow good programming practice and use variables instead of hard-coded values, but at least you should get the idea.
 
"Generally speaking, you might have been trying to use the child form's .Left, .Top, or .Location properties in an attempt to position the form. However, as you would have seen by now, this doesn't appear to work."

It works... you just have to set the StartPosition of the child form to Manual...

Alex :p
 
Back
Top