Solved

Centering Forms on any screen size.

Posted on 2006-06-21
6
178 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 250 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

623 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