Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Visual Basic
Expertise: Beginner
Oct 1, 1996



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Placing Windows on Screen

I am trying to figure out exactly how to get my window to center itself no matter what the resolution of the screen is that it is being displayed on is. I'm a beginner so go easy on me. Thank you very much.

OK...here's how you do it. The Screen object always contains the screen resolution. Put this code into your Form_Load event.

Sub Form_Load()
   Me.Top = (Screen.Height - Me.Height) / 2
   Me.Left = (Screen.Width - Me.Width) / 2
End Sub
Screen is a system object that is always available. Me refers to the current Form where this code is located. Drop this in and it will work. However, you should always check the value you're putting into the Left or Top properties to verify that it is valid. There are some strange circumstances that can cause those values to be negative.
DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date