How to Center your Form using Visual Basic 6.0

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
 

Simple code to center your form with the screen in VB 6.0.

'vb 6.0 and 5.0
Top = Screen.Height / 2 - Height / 2
Left = Screen.Width / 2 - Width / 2

Thanks to Vinz for this updated code. As he mentioned below, VB is indeed faster with multiplication than division.

 Me.Top = Screen.Height * 0.5 - Height * 0.5
 Me.Left = Screen.Width * 0.5 - Width * 0.5

One thought on “How to Center your Form using Visual Basic 6.0

  1. VinzParamore

    It should be like this:
    ‘========
    Me.Top = Screen.Height * 0.5 – Height * 0.5
    Me.Left = Screen.Width * 0.5 – Width * 0.5
    ‘========

    Because it’s faster than that code.
    Hope it helps ;D

    Reply

Leave a Reply

Your email address will not be published.