WPF Fullscreen Application - Multiple Monitors
Asked Answered
R

1

9

I've got multiple monitors that are being used with my WPF application. The application runs full screen, and I want to be able to switch which monitor it's on when the user presses a button.

case Key.M:
                    var allScreens = System.Windows.Forms.Screen.AllScreens.ToList();
                    if (this.CurrentScreen < allScreens.Count - 1)
                    {
                        this.CurrentScreen++;
                    }
                    else { this.CurrentScreen = 0; }

                    this.WindowStartupLocation = System.Windows.WindowStartupLocation.Manual;
                    this.Top = allScreens[this.CurrentScreen].Bounds.Top;
                    this.Left = allScreens[this.CurrentScreen].Bounds.Left;
                    break;

I'm trying to do this like so, but this.Left always has the value of (-7). I'm assuming it's not letting my set it because I'm full screen, but I'm not 100% sure. How can I get it to switch to the other monitor in fullscreen?

Reste answered 23/6, 2011 at 12:1 Comment(0)
U
4

As a hack, you can change the window state, send it to the other monitor and change the window state back to maximized:

this.WindowState = System.Windows.WindowState.Normal;
this.Left = screen.WorkingArea.Left;
this.Top = screen.WorkingArea.Top;
this.WindowState = System.Windows.WindowState.Maximized;

It works without any undesired effect. Just tested this.

Uncleanly answered 23/6, 2011 at 12:33 Comment(3)
I actually had the same idea myself and I've coded it just not had a chance to test it yet. Although it does seem a bit ugly (though its ugly having to ref Windows.Form for the Screens classes, but ah well).Reste
@Ian, you could probably do the same without Windows.Forms but with some direct winapi callsRoshelle
honestly, I probably prefer the WinForms reference to the API calls :) Managed to check this last night, and it did indeed work. ThanksReste

© 2022 - 2024 — McMap. All rights reserved.