RE: centering a form

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Jay Vinton (JayVinton_at_discussions.microsoft.com)
Date: 07/11/04


Date: Sat, 10 Jul 2004 19:24:02 -0700


> Anyform.left = (Screen.Width - Anyform.Width) / 2
> Anyform.tOp = (Screen.Height - Anyform.Height) / 2

If you always want it centered in the screen, set the StartUpPosition=CenterOwner at design time. At runtime, try this:

frm.Left = (Screen.Width \ 2) - (frm.Width \ 2)
frm.Top = (Screen.Height \ 2) - (frm.Height \ 2)

Jay