Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


Visual Basic Programming Code Examples

Visual Basic > Forms Code Examples

Center a form on the screen or on a MDI-form

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
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