Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Fullscreen Application - Multiple Monitors

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?

like image 296
Ian Avatar asked Jun 23 '11 12:06

Ian


1 Answers

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.

like image 196
Adrian Fâciu Avatar answered Sep 29 '22 22:09

Adrian Fâciu