Visual Basic > Forms
Center a form on the screen or on a MDI-form
Center a form on the screen or on a MDI-form Public sub CenterForm(x as Form, Optional vParent, Optional vShowMode) dim oParent as Object dim iMode% Screen.MousePointer = vbHourglass If IsMissing(vParent) Then set oParent = Screen Else set oParent = vParent end If If IsMissing(vShowMode) Then iMode = vbModeless Else _ iMode = Abs(vShowMode) Mod 2 x.Move (oParent.Width \ 2 - x.Width \ 2), ((oParent.Height \ 2 ) * .85 - x.Height \ 2) Load x x.Show iMode Screen.MousePointer = vbNormal End Sub 'use as Call CenterForm(form1) 'this will center the form1 on the screen Call CenterForm(form1,MDIform1) 'this will center the Childform1 in the MDIform1 Return
Visual Basic Codes
ActiveX
Miscellaneous
Applications
Code Snippets
Common Dialogs
Special Effects
Database Stuff
Date Time
Files Drives
Forms
Graphics Games
Internet Stuff
Multimedia
Other
Strings
Windows