Solved

Centering Forms on any screen size.

Posted on 2006-06-21
6
171 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
6 Comments
 
LVL 2

Accepted Solution

by:
cwile earned 250 total points
Comment Utility
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
Comment Utility
Me.CenterToScreen()
0
 
LVL 35

Expert Comment

by:YZlat
Comment Utility
cwile, you beat me by couple of seconds:)
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 7

Expert Comment

by:pradeepsudharsan
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

Need Help in Real-Time?

Connect with top rated Experts

5 Experts available now in Live!

Get 1:1 Help Now