Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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

Software bugs are impossible to detect by anybody except the end user.
  • 8 months later...
Posted

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.

Posted

"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

Software bugs are impossible to detect by anybody except the end user.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...