VB6


Visual Basic 6 Tutorial
By Junaid Shabbir
26-Jan-08
Views: 76709

Tips and trick of visual basic 6.
 
How to center a Form? (Page 1 of 14)

To center a form on the screen we need to know the two dimensions (screen dimension & the form dimension). Then we can easily center the form with the following two lines of code

Me.Left=(Screen.Width-Me.Width)/2
Me.Top=(Screen.Height-Me.Height)/2




Screen dimension : (1024x800) pixels
Form dimension: (700x400) pixels

Form’s left= (1024-700)/2 = 162
Form’s top= (800 – 400) / 2 = 200

We can center the child form in the MDI form with the following code

Me.Left= ( frmParent.ScaleWidth – Me.Width )/2
Me.Top= ( frmParent.ScaleHeight – Me.Height ) /2