StartPosition to CenterScreen but only on Primary Screen

Administrator

VB.NET Forum Admin
Joined
Jun 3, 2004
Messages
1,462
Programming Experience
10+
I have multiple monitors and when you have a form such as a splash form set to CenterScreen, it shows on the "active" screen. So if I launch my app and I click on the secondary monitor to read an e-mail while it's launching, the splash actually shows on the secondary monitor. Is there a way with using CenterScreen for the StartPosition to have it "center on the primary screen" or do I have to code this manually using the StartPosition.Manual and get screen bounds of the primary, etc.? Just seeing if there is an easier way to assign a form a screen to center on using the simpler CenterScreen property.
 
I think you'll have to do it manually. The doco says:
The form is centered on the current display, and has the dimensions specified in the form's size.
 
Here is what I ended up doing:

VB.NET:
        If System.Windows.Forms.SystemInformation.MonitorCount = 1 Then
            Me.StartPosition = FormStartPosition.CenterScreen
        Else
            Me.StartPosition = FormStartPosition.Manual
            Me.Location = New Point(CInt(Screen.PrimaryScreen.Bounds.Width - Me.Width) \ 2, CInt(Screen.PrimaryScreen.Bounds.Height - Me.Height) \ 2)
        End If
 
Back
Top