WPF:多屏幕

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17859414/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 09:16:57  来源:igfitidea点击:

WPF: Multiple screens

c#wpfscreensaver

提问by Nathan Friend

I'm writing a screensaver in WPF. I have the screensaver working, however, it only displays on my main monitor. Is there a way to "black out" or draw graphics to additional monitors when the user has multiple displays? I've done some searching around, but haven't found anything relevant.

我正在用 WPF 编写屏幕保护程序。我有屏幕保护程序,但是,它只显示在我的主显示器上。当用户有多个显示器时,有没有办法“黑掉”或将图形绘制到额外的显示器上?我已经做了一些搜索,但没有找到任何相关的东西。

UPDATE

更新

From ananthonline's answer below, I was able to accomplish the "black out" effect on non-primary displays using the following window:

从下面 ananthonline 的回答中,我能够使用以下窗口在非主要显示器上实现“停电”效果:

<Window x:Class="ScreenSaver.BlackOut"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Cursor="None" WindowStyle="None" ResizeMode="NoResize" Background="Black">
</Window>

and initializing one for each screen in App.xaml.csusing the following process:

App.xaml.cs使用以下过程为每个屏幕初始化一个:

foreach (Screen s in Screen.AllScreens)
{
    if (s != Screen.PrimaryScreen)
    {
        BlackOut blackOut = new BlackOut();
        blackOut.Top = s.WorkingArea.Top;
        blackOut.Left = s.WorkingArea.Left;
        blackOut.Width = s.WorkingArea.Width;
        blackOut.Height = s.WorkingArea.Height;
        blackOut.Show();
    }
}

Note an import to System.Windows.Formsis required to access the Screenclass.

请注意System.Windows.Forms,访问Screen该类需要导入到。

采纳答案by Ani

You should be able to use the System.Drawing.Screen.* classes to set up multiple windows on each screen. Mind that you don't set each window to be maximized, but a properly sized, border less window.

您应该能够使用 System.Drawing.Screen.* 类在每个屏幕上设置多个窗口。请注意,您没有将每个窗口设置为最大化,而是设置一个大小合适、无边框的窗口。

Also - you might want to remember that the total bounds of the multi monitor setup may not always be a rectangle (if you plan to "union" all the bounds to create a window spanning all monitors).

此外 - 您可能要记住,多监视器设置的总边界可能并不总是一个矩形(如果您计划“联合”所有边界以创建一个跨越所有监视器的窗口)。