detecting which screen a user drags the window to

I had been using screen(0).availableHeight and screen(0).availableWidth to adjust my main window and it works ok on Mac, but if the user on Windows drags the window to another monitor, how do I detect that it’s now on a new monitor and adjust accordingly? Should I use Window.Moved() to detect it? But how do I detect what screen it’s now on? Window.Truewindow?

You can get the screen id from the coordinates of the window. Here is a part of my code that loads a window:

[code]'set the rect
dim theRect as REALbasic.Rect
dim ToolbarHeight as Integer = ParentWindow.Bounds.Height - ParentWindow.height + 1
if ToolbarHeight = 1 then Return 'going FullScreen
if isNewPrefs then
theRect = new REALbasic.Rect(100, 100, ParentWindow.Width, ParentWindow.Height) 'dummy values
else
theRect = new REALbasic.Rect(PrefValueLeft, PrefValueTop, PrefValueWidth, PrefValueHeight)
end if

'Find screen.
Dim screenID as integer
For l as integer = 0 to screenCount - 1
if theRect.top >= screen(l).top and theRect.center.x > screen(l).left and theRect.center.x < (screen(l).left + screen(l).width) then screenID = l
next[/code]

The code is executed when a window is opened and when it’s moved.

thanks, Beatrix. I’ll play around with that and see if I can get it to work too.