Centering Forms on any screen size.
Posted on 2006-06-21
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.