Why are you using both
SetDesktopLocation
and
Location
? They both do the same thing in subtly different ways:"
1.
SetDesktopLocation[
^]
Quote:
Sets the location of the form in desktop coordinates.
2.
Location[
^]
Quote:
The Point that represents the upper-left corner of the Form in screen coordinates.
Choose the right one, do not use both.
For multiple Screens you need to work with the
Screen Class (System.Windows.Forms) | Microsoft Learn[
^]
You can check the number of screens available:
Dim screenCount = Screen.AllScreens.Count()
Then you can set the location in the approriate screen based on the number of screens available:
Dim x = 200
Dim y = 200
Dim screenLocation = Screen.AllScreens(screenCount - 1).WorkingArea.Location
Me.Location = New Point(x + screenLocation.X, y + screenLocation.Y)
UPDATE
I do not have a second screen to test with, however, looking at
Screen.Bounds Property (System.Windows.Forms) | Microsoft Learn[
^], an alternative would be to set the
Form.DesktopBounds Property (System.Windows.Forms) | Microsoft Learn[
^].
Dim x = 200
Dim y = 200
Dim monitor = Screen.AllScreens _
.Where(Function(scr) Not scr.Primary) _
.FirstOrDefault()
If monitor Is Nothing Then
monitor = Screen.AllScreens _
.Where(Function(scr) scr.Primary) _
.First()
End If
Me.DesktopBounds = monitor.WorkingArea
Me.Location = New Point(x, y)
Hope this helps.