devxlogo

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.

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  How Seasoned Architects Evaluate New Tech

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.