Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I center a form?

Forms

How can I center a form?

by  Michael42  Posted    (Edited  )
'''MDI Example (Child From)
'''Place in Form_Load
Me.Left = (MDIMain.ScaleWidth - Me.Width) / 2
Me.Top = (MDIMain.ScaleHeight - Me.Height) / 2

===
''' SDI Example
''' Place in Forms's Form_Resize () or Form_Load() Event
'Centers Form (if not minimized or maximized.)
If WindowState = 0 Then
Move (Screen.Width - Screen.ActiveForm.Width) / 2, (Screen.Height - Screen.ActiveForm.Height) / 2
End If
===
''' SDI (Using Sub)
'''Usage: sCenterForm Me

Sub sCenterForm (mForm As Form)
Dim mTop As Integer, mLeft As Integer
If mForm.WindowState <> 0 Then Exit Sub
mTop = (Screen.Height - mForm.Height) \ 2
mLeft = (Screen.Width - mForm.Width) \ 2
mForm.Move mLeft, mTop

End Sub
===
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top