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
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist