WPF全屏应用程序-多个监视器

9

我有多个显示器与我的WPF应用程序一起使用。该应用程序以全屏方式运行,我希望用户按下按钮时能够切换它所在的监视器。

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;

我试图这样做,但是this.Left的值始终为(-7)。我猜测它不让我设置它是因为我全屏了,但我不确定。如何在全屏模式下切换到另一个显示器?

1个回答

4
作为一种技巧,您可以更改窗口状态,将其发送到另一个监视器,并将窗口状态更改回最大化:
this.WindowState = System.Windows.WindowState.Normal;
this.Left = screen.WorkingArea.Left;
this.Top = screen.WorkingArea.Top;
this.WindowState = System.Windows.WindowState.Maximized;

它没有任何不良影响,已经测试过。


我其实也有同样的想法并且已经编写了代码,只是还没有机会进行测试。虽然它看起来有点丑陋(尽管在屏幕类中必须引用Windows.Form看起来很丑陋,但没关系)。 - Ian
@Ian,你可能可以不使用Windows.Forms,而是使用一些直接的winapi调用来完成相同的操作。 - Adrian Fâciu
老实说,我可能更喜欢WinForms参考文档而非API调用 :) 昨晚设法检查了一下,确实可以工作。谢谢 - Ian

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接