【问题标题】:WPF Fullscreen Application - Multiple MonitorsWPF 全屏应用程序 - 多个监视器
【发布时间】:2011-06-23 12:01:23
【问题描述】:

我的 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% 确定。如何让它全屏切换到另一台显示器?

【问题讨论】:

    标签: wpf multiple-monitors


    【解决方案1】:

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

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

    它没有任何不良影响。刚刚测试过。

    【讨论】:

    • 实际上我自己也有同样的想法,我已经编写了代码,只是还没有机会测试它。虽然它看起来确实有点丑(虽然它丑得必须为 Screens 类引用 Windows.Form,但是很好)。
    • @Ian,如果没有 Windows.Forms,但有一些直接的 winapi 调用,您可能也可以这样做
    • 老实说,我可能更喜欢 WinForms 对 API 调用的引用 :) 昨晚设法检查了这一点,它确实有效。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 2016-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多