On Windows customer has 3 monitors. Drags our app after open to 2nd monitor.
When he opens a new window it opens on the main monitor not the one where the main window is.
How do I get the new windows to keep from going to the main monitor?
Also, my File Open or New dialog and other dialogs on Windows show up in the far upper left. They are set to “Default” placement.
Is that correct or should the popup in the middle of the main window?? For large monitors it’s odd that they appear
so far in the upper left.
This is what I use to center a window on a given screen:
[code]
Sub ShowCentered(Win As Window, ScreenNumber As Integer = 0)
’ Shows the passed window centered on the specified Screen.
Dim X, Y As Integer
X = (0.5 * Screen(ScreenNumber).Width) - (0.5 * Win.Width)
Y = (0.5 * Screen(ScreenNumber).Height) - (0.5 * Win.Height)
win.Show
If Screen(ScreenNumber).Top > Screen(0).Height - 1 Then
Y = Y + Screen(ScreenNumber).Height
End If
If Screen(ScreenNumber).Left > Screen(0).Width - 1 Then
X = X + Screen(ScreenNumber).Width
End If
win.Left = X
win.Top = Y
End Sub[/code]
And to calculate which screen a window is on:
[code]
Function ScreenFromXY(X As Integer, Y As Integer) As Integer
Dim rect As New REALbasic.Rect
Dim pt As New REALbasic.Point
pt.X = X
pt.Y = Y
For i As Integer = 0 To ScreenCount - 1
rect.Top = Screen(i).Top
rect.Left = Screen(i).Left
rect.Width = Screen(i).Width
rect.Height = Screen(i).Height
If rect.Contains(pt) Then
Return i
End If
Next
Return -1
End Function[/code]
e.g.
Dim n As Integer = ScreenFromXY(Parent.Left, Parent.Top)
ShowCentered(ChildWindow, n)
Again since I can’t test it with multiple monitors… does this code work for both Mac and Windows?
(I don’t even know if macs support multiple monitors… sad I know)
Do either MS User Guidelines or Apple Human Interface Guidelines say that dialogs can or cannot be centered vs. some other location?
I did try to set one dialog to parent window thinking it would center in the middle or up top of its parent but still showed up to the left.
I am mixing questions I guess… the one about not having dialogs pop up in the upper left corner instead of near the main window… I tried changing the Placement to different options and did not see a change. I will read up on that.
As for multiple monitors, from feedback from my client and from the others on this thread it defaults back to the main monitor unless you do something about it and the Placement doesn’t help?? I’m assuming that’s why @Andrew Lambert posted the code that he did…
Behavior --> Placement --> Parent WIndow Screen ?
AFAIK, it will place the newly opened window to the screen (monitor) where an already opened window resides.
So, if you have a window in Monitor #3, the window that have this setting will be opened in Monitor #3.
The documentation says this:
Placement can take on the following values:
Value Description
0 Default
1 Parent Window
2 Main Screen
3 Parent Window Screen
4 Stagger
But it doesn’t define what those mean at all. I could easily test them with trial and error but I don’t have a multi monitor system.