Dual Screens postioning

Sigh… 31201 is from 2013 which is really really sad.

Have you tried

Me.Left = 0

That should position the window left of screen(0). It does not matter if each screen has a different resolution.

That was the first thing I tried, generally all of my apps I put Me.Left = 0 and Me.Top = 0 in the Open event handler.

do you use
Window1.Show

or
Var w As New Window1
w.Show
?

this implicit instance could behave different if you will set your position

I have it in the Open event handler of the Window1 control.

I’ve tried many combinations by changing the default location of the behavior in the control menu and none of them changed it. I got close by using “me.Left = ((Screen(1).AvailableWidth-me.Width)/2) + 511”. It basically puts the window to the left of screen(0) (Main Display 1024) and I have to move it to the right. This worked until I got to + 512, I assume since 512 is half of 1024 it hits that point and moves it to the bigger screen. In all instances when you move it over to a certain point it jumps all the way over to the second screen. I could probably live with it being moved over to + 511 as it just adds a little bit of a black bar to the left of the TV. Not the best result but it’s as close as I can get to how I would want it to work. I guess I’m too used to VB/VB.net where you set left = 0, top = 0 and it put the app at the top left of your main display.

Check your screen’s scaling eg 100 % or 150 or 175 etc. Set them both to the same or 100% and try again.

From what I can tell the main display top & left is always 0, 0 with other displays relative to that. I wrote a little project to visualize the various positions which you can download from here
My layout looks like this with the bottom right being my main screen.

have also a look at .bounds
https://documentation.xojo.com/api/deprecated/window.html#window-bounds

but i guess your problem is the auto position by xojo.

Function WhichScreen(x As Integer, y As Integer) As Integer
		  		  
		  For i As Integer = 0 To ScreenCount-1		    
		    If x >= Screen(i).Left And x < Screen(i).Left + Screen(i).Width And y >= Screen(i).Top And y < Screen(i).Top + Screen(i).Height Then		      		      
		      Return i 
		    End If 
		  Next
		  
		  Return 0
		  
End Function

Sub CenterOnScreen(s As Integer, w As Window)
		  
		  w.Left = Screen(s).Left + (Screen(s).AvailableWidth - w.Width) / 2 
		  w.Top  = Screen(s).Top + (Screen(s).AvailableHeight - w.Height) / 2
		  		  
		  If w.Left < 0 Then w.Left = 0
		  If w.Top < 0 Then w.Top = 0
		  
End Sub
Var win As WindowPlanung = WindowPlanung
win.Show
Var s As Integer = WhichScreen(MouseX, MouseY)
CenterOnScreen(s, win)

Error 404. Sorry Wayne.

There are known issues with Xojo… especially when it comes to Multi-Monitors that have different Scaling.

That’s exactly what we are doing… to get a reliable positioning on TargetWindows.

If you want to give the Declares approach a try… then have a look at this example project: Monitors

Using the (Pos)-Buttons on the right hand side a dialog window is being positioned using Declares on TargetWindows. That seems to work reliably for us.

There is a Window Extension Method allowing you to position at a defined position on a defined Screen/Monitor:

Dim w As New MyDialogWindow
w.SetPosition_AtMonitorPosition(iMonitor, iPosX, iPosY)
w.Show(Modal)

If you give this example project a try, I’m curious to know if it work in your situation/environment, too.

1 Like

Wayne, the issue I am having is with the main screen having a resolution that is lower than the others. I was having no issue when the main screen resolution is higher than the others (like your example).

Thanks Jürg. This sounds like what I am dealing with. My second monitor is a TV which has the scaling set to full-screen(through Nvidia console) and the smaller main screen is a monitor set to default scaling. I’ll give your program a try and let you know how it works.

1 Like

I created another topic related to this one a short time ago because my search missed this post. Jürg’s code resolved all the issues in my app with respect to accurate placement of a window on a specific display. However, I have not been able to resolve the issue of the window splitting across 2 displays when the displays have different scale settings and Fullscreen=true.

I hope that the updated example mentioned in the other Thread you’ve created might work for FullScreen=true, too.
If not, it still might give an idea how to tackle it…

Jürg, I had a chance to try the examples in your project and it is a handy tool. I’m trying to remove the titlebar from my program so I use a moveable modal window with no caption which works but when I use SetPosition_AtMonitorPositionyour it shows the titlebar and I’m unable to position the window at -30 to move it up and not show the titlebar. No matter where I move it off the screen it keeps going back to 0,0. Am I doing something wrong?

Correct - that’s a feature :wink:

The example always makes sure to call: windowInstance.FitOnMonitor. This makes sure that even when trying to position at a “wrong location”, the full content of the Window is being shown and visible.
And since your MoveableModal has a TitleBar, it’s expected to show and be visible.

Having said that… you can still use the example project and modify it according to your needs :wink:

Makes sense, sounds good. Last question, I also noticed that the windows in my app have a blue outline / focus window around them when they are the top window. Since you seem to know the API’s well is there an API to remove the blue outline around the window when it is the active window?

Not really… Google is my friend for such matters :wink:

Google… shows this Forum Thread: Desktop app without title and border

I’ve just tried and added the following code to “Window2 → Event: Open” in the example project:

#If TargetWindows Then
Declare Function SetWindowLongW Lib "User32" (HWND As Integer, Index As Integer, NewLong As Integer) As Integer
Const GWL_STYLE = -16
Const WS_POPUP = &h80000000
Call SetWindowLongW(Me.Handle, GWL_STYLE, WS_POPUP)
#EndIf

Looks good to me. But then again - I don’t really know if that’s what you’re looking for.
Or a couple of replies above there is a link to another Thread by Karen. That one is about “fullscreen” - just in case that’s what you’re after.

Anyway… I’ll be without a computer for more than two weeks very soon, enjoying other things… so don’t expect anything from me meanwhile :wink:

Thanks for looking into it. I really appreciate it. I’ll throw a couple bucks in your paypal for the program you passed on.