devxlogo

Placing Windows on Screen

Placing Windows on Screen

Question:
I am trying to figure out exactly how to get mywindow to center itself no matter what the resolution of the screen is that it is beingdisplayed on is. I’m a beginner so go easyon me. Thank you very much.

Answer:
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) / 2End 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.

See also  Does It Make Sense to Splurge on a Laptop?
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