tags:

views:

258

answers:

4

I am writing a programme to be used internaly within our company and have come across the problem below:

How can you get a Child form to centre on the screen when using the MDI parent maximised form as the backgroung

A: 

Select from the properties in the IDE on the bottom right the WINDOWS PROPERTY - CENTER PARENT. It may be named something a little difference but is in the drop down with CENTER SCREEN

EDIT: I think it is WINDOWS POSITION - CENTER PARENT

Todd Moses
It has been many years since I used VB6.
Todd Moses
If you try to set the StartUpPosition for an MDI Child form to anything other than Manual, you get an error: "Invalid Property Value".
G Mastros
+1  A: 

In the MDI child screen, create a Form_Initialize function like this:

Private Sub Form_Initialize()

    Me.Left = (MDIForm1.ScaleWidth - Me.Width) / 2
    Me.Top = (MDIForm1.ScaleHeight - Me.Height) / 2

End Sub

Of course, you'll need to substitute the name of your MDI form where you see MDIForm1 in the code above.

G Mastros
A: 

From Microsoft: "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."

From the parent:

Private Sub MDIForm_Load()
    CenterChildForm MDIForm1, Form1
End Sub

Sub CenterChildForm(Parent As Form, Child As Form)
     If Parent.WindowState = 1 Then Exit Sub 'The Parent is minimized, centering is invalid.

     Child.Top = (Parent.ScaleHeight - Child.Height) / 2
     Child.Left = (Parent.ScaleWidth - Child.Width) / 2
End Sub

From the Child:

Private Sub Form_Load()
    Me.Left = (MDIForm1.ScaleWidth - Me.Width) / 2
    Me.Top = (MDIForm1.ScaleHeight - Me.Height) / 2
End Sub
jasonk
A: 

As an addition to the above use the me.Move [left], [top], [width], [height] method

it is quicker and performs the positioning in a single action.

Murray