Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Centering Forms on any screen size.

Posted on 2006-06-21
6
Medium Priority
?
180 Views
Last Modified: 2010-04-23
This question is worth 250 points and they will be awarded to the person that provides the best solution.

I have an application containing a Form that changes sizes depending on user input. At load the Form is  3" high X 2" wide and if the user clicks a check box on the Form it changes to 3" high X 6" wide. Once the user inputs some info into the Form the Form returns to the 3" X 2" size. My problem is positioning the Form in the center on load for different screen sizes. If I use a laptop with a wide screen it loads differently that if I use a desktop with a 17" monitor. Needless to say that using the automatic "Center Form" property does not work on the wide screen for some reason. The code I'm using to try and get around this is below:

Me.Size = New Size(m_intX1, m_intY)
Dim intX As Integer = 0
Dim intY As Integer = 0
intX = (Me.ClientSize.Width / 2)               ' Adjust Form to center of screen
intY = (Me.ClientSize.Height / 2)              ' Adjust Form to center of screen
Me.Location = New Point(intX, intY)          ' Relocates the Form to the center of ANY screen  

However, this doesn't seem to work for every case and different screen sizes and shapes. Any thoughts?

Thanks in advance for your help.
0
Comment
Question by:Mr_Fulano
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 2

Accepted Solution

by:
cwile earned 1000 total points
ID: 16950862
Have you tried just adding this to the places you wish the form to be centered?

Me.CenterToScreen()

I have a 17" widescreen laptop and that works just peachy for me.
0
 
LVL 35

Expert Comment

by:YZlat
ID: 16950863
Me.CenterToScreen()
0
 
LVL 35

Expert Comment

by:YZlat
ID: 16950875
cwile, you beat me by couple of seconds:)
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 7

Expert Comment

by:pradeepsudharsan
ID: 16950885
Hi,

try like this

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.StartPosition = FormStartPosition.CenterScreen
    End Sub

regards
pradeep
0
 
LVL 7

Expert Comment

by:pradeepsudharsan
ID: 16951385
Hi,

try like this


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Me.Left = (Screen.PrimaryScreen.WorkingArea.Width - Me.Width) / 2
        Me.Top = (Screen.PrimaryScreen.WorkingArea.Height - Me.Height) / 2

 End Sub

regards
pradeep
0
 

Author Comment

by:Mr_Fulano
ID: 16973589
Everyone contributed very nicely, however, cwile came up with a solution that worked first, so I awarded him the points. I appreciate all your help.

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question