Postioning a window at runtime - driving us crazy!

We have a windows desktop application running on W11Pro using Xojo 2025v2.1
It makes use of 2 displays - the main (1920x1080) and a smaller screen aligned on the left (1200x600).

The application contains several ‘customer facing’ windows which are displayed on the secondary display - each window is sized to exactly 1200x600.

At runtime, there’s a small method which checks for more that one display connected (the smaller screens can be temperamental so sometimes disconnect or get switched off by staff even). If a second display is detected, the position of the window is modified to shift it left by (-width) pixels.

Sub ShowOnClientScreen (Extends Window as DesktopWindow, AlwaysDisplay as Boolean)

If DesktopDisplay.LastDisplayIndex>0 Then
  
  //position window on small monitor to left
  Window.Top = app.kSecondaryScreenTop (480 which is 1080 - 600)
  Window.Left = app.kSecondaryScreenLeft (-1200)
  
Else
  
  If Not AlwaysDisplay Then
    //hide if no extra display detected
    Window.Hide
  End If
   
End IF

This sort of works fine but we’ve noticed a few pixels are overlapping the main screen, or we even see a white bar on the bottom and left of the second screen in one instance. Lots of testing leaves us puzzled as to what’s actually going on.

By way of highlighting the issue, I added a small yellow square in 2 corners of one window layout as shown..

..and modifed the runtime method to just move the window to 0,0 which should be the top left of the main display. It seems this is problematical as shown - at runtime, the window is clearly moved beyond the left and top, leaving behind a white area.

A system.debuglog of the window’s size and position returns 1200x600 and 0,0 as expected.

Potentially related, a different window seems to have gained a white border, although it doesn’t look like it’s been shifted in this case. This is a modal window whereas the one above is not.

I should add that these windows do not have ‘explicit instance’ selected as they have a ShowX method to open them with some passed parrameters.

Sub ShowX(PinNumber as integer)

PinOK=False
ClientPIN=PinNumber

If PinNumber=-1 Then
  //prompt for a new pin
  ConfirmTitle.Text="Enter a new 4 digit PIN number then click GO.."
Else
  //prompt for existing pin
  ConfirmTitle.Text="Please enter your 4 digit PIN number then click GO.."
End If

self.ShowModal

I guess Windows is intervening somehow but can anyone explain exactly what’s going on here please and more importantly, how to accurately position a window? We’ve tried various settings for Window Type and Default Location but are unable to identlfy the issue or any logic.

Any help appreciated, Thanks

Instead set the bounds instace of the window to a rect of the size you want.

also set fullscreen = true that should help

2 Likes

In the documentation, you will find that in DesktopWindow Bounds

2 Likes

Thanks for both replies, issue completely resolved by using Bounds. I can’t honestly say I appreciate fully why it was needed but I changed the code as follows and now everything is pixel-perfect so very happy :grinning_face:

Sub ShowOnClientScreen (Extends Window as DesktopWindow, AlwaysDisplay as Boolean)
If DesktopDisplay.LastDisplayIndex>0 Then
  
  //set bounds of window to match small monitor to left
  Var myBounds As New Rect
  myBounds.Left = - app.kSecondaryScreenWidth
  myBounds.Top = DesktopDisplay.DisplayAt(0).Height - app.kSecondaryScreenHeight
  myBounds.Height = app.kSecondaryScreenHeight
  myBounds.Width = app.kSecondaryScreenWidth
  Window.Bounds = myBounds
  
Else
  
  If Not AlwaysDisplay Then
    //hide 
    Window.Hide
  End If
  
  l4x.Log "No secondary display found", Log4Xojo.LogLevel.Error, CurrentMethodName
  
End IF
End Sub

Thanks again!

2 Likes