Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Center a form on the screen 1

Status
Not open for further replies.

RonRepp

Technical User
Feb 25, 2005
1,031
US
Hi all:

This should be a no-brainer, but I have a form that will not center on the screen in spite of setting the startup position as Center Screen.

As you can see, I've tried a few different things, but nothing seems to work.

Code:
 'Me.StartPosition = FormStartPosition.CenterScreen
        Dim P As Point = New Point(System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.X, System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Y)
        
        RefreshForm()
        sTime = Now
        eTime = sTime
        dtDown.Value = sTime
        dtUp.Value = eTime
        SetMainForm = Me
        'Me.SetDesktopLocation((P.X - Width) / 2, (P.Y - Height) / 2)
        Visible = True
        Refresh()

Any help will be greatly appreciated.

Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.
 
Private Sub form_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

Me.CenterToParent()
 
llmclaughlin:

I busted my brain for hours trying to figure out why it didn't center.

Thanks; and a star for you.



Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.
 
RonRepp,

You can also use
Code:
Me.Left = (Screen.PrimaryScreen.WorkingArea.Width - Me.Width) / 2
Me.Top = (Screen.PrimaryScreen.WorkingArea.Height - Me.Height) / 2
This will work if the person using the application has dual monitirs.

Senior Qik III, ASP.Net, VB.Net ,SQL Programmer

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SELECT * FROM Users WHERE clue > 0
0 Rows Returned

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top