Self.Left = Screen(0).AvailableWidth + ((Screen(1).AvailableWidth - Self.Width) \\ 2)
Crash with probably an OutOfBounds exception in the IDEs debugger.
When compiled with 2015r1, the same project runs fine. (in fact, I generated the application with 2015r1 yesterday and use it minutes ago without any Exception.
Obviously, the code center the front window and not obviously, at this moment I only have the built-in Retina display in this MacBook Pro.
BTW: how do I get back to the offending code (seen in the debugger) after I left the running application ?
Good catch Jean-Paul !
I may have to count the number of screens before doing that !
Screen(1) usually is the monitor I used to watch TV on
and, still usually, is conencted to my WIndows 10 laptop ;-:).
I also have to check when this part of the code is executed too.
If it’s about centering your Window, this is how I do it.
On OS X, it also handles the Dock (bottom, left, hidden etc.) and on what screen your Window is on:
// Center Window
// Get current Screen
Dim thisScreen As Integer
For i As Integer = 0 To ScreenCount - 1
If TrueWindow.Left >= Screen(i).Left And TrueWindow.Left < Screen(i).Left + Screen(i).Width And TrueWindow.Top >= Screen(i).Top And TrueWindow.Top < Screen(i).Top + Screen(i).Height Then
thisScreen = i
Exit For i
// Set Bounds
Dim myBounds As New Realbasic.Rect
myBounds = Self.Bounds
myBounds.Left = (Screen(thisScreen).AvailableWidth \ 2) - (myBounds.Width \ 2) + Screen(thisScreen).AvailableLeft
If myBounds.Left < Screen(thisScreen).AvailableLeft Then
// Adjust if Window is wider than screen
myBounds.Left = Screen(thisScreen).AvailableLeft
myBounds.Top = (Screen(thisScreen).AvailableHeight \ 2) - (myBounds.Height \ 2) + Screen(thisScreen).AvailableTop
If myBounds.Top < Screen(thisScreen).AvailableTop Then
// Adjust if Window is taller than screen
myBounds.Top = Screen(thisScreen).AvailableTop
Self.Bounds = myBounds[/code]
BTW: how do I get back to the offending code (seen in the debugger) after I left the running application ?[/quote]
I haven’t found a proper way other than clicking the pencil icon at the top. But that leaves the App running and when you quit it, the tab closes.
There’s actually a
center function for NSWindow because on Mac we’re used to a centered window being slightly above center. The declare probably isn’t all that difficult if you’re set on trying to get a consistent Mac feel.
It is already in MacOSLib, Windows Extensions.
And included with the Xojo examples:
Examples/Platform-Specific/OS X/Cocoa Declares
Thank you: code works fine.
BTW: the project runs also on Windows. Declare code to share ?
I searched the whole yesterda’s afternoon to nothing.
I discovers minutes ago that the OS X code center in both Horizontal and Vertical the window. Nice !
Nota: I am never happy with some results. Sometimes I want to have the window centered, sometimes stick keft or right or
At last I stay with my first idea or the behavior I used the most often and let the other cases to "a mouse move.