Hi,
Im not able to center a child form of a parent MDIForm (MDIForm1) it shows up error message "Invalid property value" while setting the StartUpPosition property to 1-CenterOwner, or 2-CenterScreen, or 3-WindowsDefault of the child form.

How can I set all the StartUpPosition property of the child form?

Please help!

Recommended Answers

All 7 Replies

You have to calculate the distance, and use form.move....in a module (normal code module, not class) add this:

Sub DoCenter(child As Form, parent As Form)
Dim mTop As Integer
Dim mLeft As Integer

If parent.WindowState <> vbNormal Then Exit Sub
mTop = ((parent.Height - child.Height) \ 2)
mLeft = ((parent.Width - child.Width) \ 2)
child.Move mLeft, mTop
End Sub

Then whenever you want to center the form, just call DoCenter mdiChild, mdiParent

You have to calculate the distance, and use form.move....in a module (normal code module, not class) add this:

Sub DoCenter(child As Form, parent As Form)
Dim mTop As Integer
Dim mLeft As Integer

If parent.WindowState <> vbNormal Then Exit Sub
mTop = ((parent.Height - child.Height) \ 2)
mLeft = ((parent.Width - child.Width) \ 2)
child.Move mLeft, mTop
End Sub

Then whenever you want to center the form, just call DoCenter mdiChild, mdiParent

Sorry my friend this did not work !!!
Any other ideas ?

Hmmm, worked great for me.

Why can't you just put centering code in the Form_Load event of the mdi child form? You know what window will be the parent, and it wouldn't matter is the parent is maximized or normal.

Hi,

You cannot set the Start-Up position for the MDI Child forms in VB6..
This is from MSDN Help:
The initial size and placement of MDI child forms are controlled by the Microsoft Windows operating environment unless you specifically set them in the Load event procedure.

So You can write this code in MDI, wherever, you want to show the form..:

Form1.Show
Form1.Move (Me.Width - Form1.Width) / 2, (Me.Height -  Form1.Height - 800) / 2

Note 800: Approx Height of MDI TitleBar +Windows Start/TaskBar

Regards
Veena

Thanks
that all sure did help !

In the form load of the form you want to center put this code

Me.Move (mdiMain.Width - Me.Width) / 2, (mdiMain.Height -  Me.Height) / 2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.