center a child form in a MDI 
Author Message
 center a child form in a MDI

Could someone tell me how to centre a child form in a MDI? Im sure there is
a simple answer to this??

Thanx!!

J



Mon, 27 Oct 2003 03:50:25 GMT  
 center a child form in a MDI
In Form_Load size the window with the Move method or the Top, Left, Width
and Height properties.


Quote:
> Could someone tell me how to centre a child form in a MDI? Im sure there
is
> a simple answer to this??

> Thanx!!

> J



Mon, 27 Oct 2003 05:13:31 GMT  
 center a child form in a MDI
The Move method is probably better because it means you only need to make
one call.  This is the procedure we use:

' Centre one form relative to another.
Public Sub CentreForm(objMainForm As Form, objChildForm As Form)

    Dim sngNewX As Single
    Dim sngNewY As Single
    Dim sngMainFormX As Single
    Dim sngMainFormY As Single

    On Error Resume Next

    If Not objChildForm.MDIChild Then
        sngMainFormX = objMainForm.ScaleLeft
        sngMainFormY = objMainForm.ScaleTop
    End If

    sngNewX = (objMainForm.ScaleWidth - objChildForm.Width) / 2 +
sngMainFormX
    sngNewY = (objMainForm.ScaleHeight - objChildForm.Height) / 2 +
sngMainFormY

    If sngNewX < 0 Then sngNewX = 0
    If sngNewY < 0 Then sngNewY = 0

    objChildForm.Move sngNewX, sngNewY
End Sub


Quote:
> In Form_Load size the window with the Move method or the Top, Left, Width
> and Height properties.



> > Could someone tell me how to centre a child form in a MDI? Im sure there
> is
> > a simple answer to this??

> > Thanx!!

> > J



Mon, 27 Oct 2003 21:08:51 GMT  
 center a child form in a MDI
The move method is not probably better, it's better.

Each reference to the top, left, height or width property will cause a
repaint to occur. With move repainting happens only once. So your code will
be faster.

This is especially important when your replacing and resizing controls while
a form is resized.



Quote:
> The Move method is probably better because it means you only need to make
> one call.  This is the procedure we use:



Tue, 28 Oct 2003 05:18:31 GMT  
 center a child form in a MDI
That's exactly what I meant.  I put the "probably" in as a habit of speech.
Quote:

> The move method is not probably better, it's better.

> Each reference to the top, left, height or width property will cause a
> repaint to occur. With move repainting happens only once. So your code will
> be faster.

> This is especially important when your replacing and resizing controls while
> a form is resized.



> > The Move method is probably better because it means you only need to make
> > one call.  This is the procedure we use:



Tue, 28 Oct 2003 15:43:12 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Centering a child form in an MDI Window

2. Center an MDI Child in MDI form

3. Q: Form activate Fires On Non Child MDI Forms But Only Once On Child Mdi Forms

4. MDI Child Form Centering

5. Centering MDI Child Form

6. Centering child form in MDI

7. Q: Centering an MDI Child Form

8. Center MDI Child Form

9. Centering child form in mdi window

10. How to center the MDI Child form when it is loaded

11. Newbie Question - Center MDI child form

12. How to center MDI child form

 

 
Powered by phpBB® Forum Software