Recommand · June 10, 2021 0

Is there a proper way of opening a window in the center of the screen that contains the mouse cursor?

I’ve seen a lot of good solutions to this problem, but none of them seam to work for all my cases.
My biggest problem is that the WindowStartupLocation property of the window doesn’t seam to work correctly (.NET 4.7.2). In the description of the enum it says that the value of CenterScreen opens the window in the center of the screen that contains the mouse cursor.
In my case it seams to be opening in the center of the screen that contains the owner window of the window I try to open.
I checked a bit what the WindowManager from Caliburn Micro does and it indeed sets the owner of the window to the main window of the application if I don’t specify an owner. This main window is opened on the correct screen according to the startup location description, but I want to open message boxes and popups anywhere, not just on the first screen.
If I explicitly set the owner to null, it’s no longer centered in a lot of cases related to different DPI monitors.
I also tried to move the main window of the application, which is invisible, to the cursor location and that partially solved the problem on my dev machine, indicating that CenterScreen indeed goes to the screen where the owner is, not where the mouse cursor is. But on the tester’s machine, it wasn’t centered at all on the last 2 of 3 screens (1 laptop 125% and 2 monitors 100%).
What else can I try? Maybe related to owner relations, maybe there is something that I missed in the Caliburn WindowManager?