Change startup location of a form based on screen resolution (VB.NET)

Soldato
Joined
20 Jan 2005
Posts
2,722
Location
Whitley Bay
Hi there,

I'm trying to find a way of changing the startup location of a form depending on the screen resolution of the primary monitor.

By default the startup position is set to manual with a location of (0, 0).

As the form size is optomised for 1024x768 I want to centre the form if the screen width is greater than 1024.

I've got something along the lines of:

Dim screenWidth As Integer = My.Computer.Screen.Bounds.Width
If screenWidth > "1024" Then
Main.StartPosition = FormStartPosition.CenterScreen
Main.Show()
End If

It isn't changing the location unfortunately.
I'm probably overlooking something simple but any help would be appreciated!

Thanks

Si
:)
 
Where are you putting that code? Obviously it's only going to do anything if it's run before the form is shown, so try putting it in the form's constructor.
 
Back
Top Bottom