devxlogo

Center Forms Onscreen

Center Forms Onscreen

I use this procedure to center my forms. With frmParent, the lastloaded form is centered against the parent form. Otherwise, it’scentered against the screen. I always center forms in the Loadevent and often forget to put Me as the parameter. To center anyform, put CenterForm in the Form_Load event:

 Public Sub CenterForm(Optional _        frmParent)If Forms.Count = 0 Then Exit SubIf IsMissing(frmParent) Or Not TypeOf _        frmParent Is Form Then         Forms(Forms.Count - 1).Move _                (Screen.Width - _                Forms(Forms.Count - _                1).Width) / 2, _                (Screen.Height - Forms(Forms. _                Count - 1).Height) / 2Else        Forms(Forms.Count - 1).Move _                (frmParent.Width - Forms(Forms. _                Count - 1).Width) / 2, _                (frmParent.Height - _                Forms(Forms.Count - _                1).Height) / 2End IfEnd Sub

devx-admin

Share the Post: