WPF 全屏应用程序 - 多显示器

发布于 2024-11-17 02:17:19 字数 758 浏览 3 评论 0原文

我的 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)。我假设它不允许我设置它,因为我是全屏的,但我不能 100% 确定。如何让它全屏切换到另一台显示器?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷清清 2024-11-24 02:17:19

作为一种黑客,您可以更改窗口状态,将其发送到另一个监视器并将窗口状态更改回最大化:

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

它可以正常工作,不会产生任何不良效果。刚刚测试过这个。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文