Link to home
Start Free TrialLog in
Avatar of InvisibleMan
InvisibleMan

asked on

How to open a form centered?

How do I make sure a form opens in the center of my screen?  Thanks
Avatar of vinnyd79
vinnyd79

Set the forms StartUpPosition to  'CenterScreen'
ASKER CERTIFIED SOLUTION
Avatar of ChenChen
ChenChen
Flag of Afghanistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Above 2 ways you can centre the screen,
Make sure that once you set the startupPosition property, you do not drag the window or change the position [that resets the startupPosition property]
I agree with the above, but I also like to keep the form invisible, until it is sized and/or centered.

Set Visible = False

in the Form_Load() event

'Size it first if necessary...

Me.Left = (Screen.Width - Me.width) / 2
Me.Top = (Screen.Height - Me.height) / 2

Doevents
Me.Show

This makes sure all of the moving around is finished before the user sees it.

Avatar of InvisibleMan

ASKER

Can someone give me a function or sub I could call to make sure they open in center view?  Thanks. This way I can pass in a form.