Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 多监视器应用程序如何检测丢失的监视器_C#_Wpf_Multiple Monitors - Fatal编程技术网

C# 多监视器应用程序如何检测丢失的监视器

C# 多监视器应用程序如何检测丢失的监视器,c#,wpf,multiple-monitors,C#,Wpf,Multiple Monitors,具有停靠功能的应用程序可以使用所有窗口(包括单独显示器上的窗口)的位置保存桌面 如果重新加载保存的桌面,但一个或多个监视器未连接,则应用程序应检测到此情况。 我有以下资料: ... Windows windows = Window.GetWindow(pane); if (window != null) { PaneTookWindow = toolWindow = window.Content as PaneToolWindow; if

具有停靠功能的应用程序可以使用所有窗口(包括单独显示器上的窗口)的位置保存桌面

如果重新加载保存的桌面,但一个或多个监视器未连接,则应用程序应检测到此情况。 我有以下资料:

    ...
    Windows windows = Window.GetWindow(pane);
    if (window != null)
    {
      PaneTookWindow = toolWindow = window.Content as PaneToolWindow;
      if (toolWindow != null)
      {
        if (!AreaInScreenBounds(new Rect(toolWindow.Left, toolWindow.Top, toolWindow.Width, toolWindow.Height)))
        {
           pane.ExecuteCommand(ContentPaneCommands.ChangeToDocument);
        }
      }
    }
    ...


   private static bool AreaInScreenBounds(Rect area)
   {
      if (Application.Current != null && Application.Current.MainWindow != null)
      {
         Rect [] screeAreas = Application.Current.MainWindow.GetScreenAreas();
         return screenAreas.Any(screen => screen.Contains(area));
      }
      return false;
   }
问题在于,此方法不会检测监视器是否不再可用,而是检测该区域是否在主窗口区域之外


有人知道如何检测断开连接的监视器或不再可用的区域吗?

屏幕类表示单个系统上的一个显示设备或多个显示设备。您应该需要分辨率的“Bounds”属性和连接的显示器数量的“AllScreens”属性

int index;
int upperBound; 
Screen [] screens = Screen.AllScreens;
upperBound = screens.GetUpperBound(0);
for(index = 0; index <= upperBound; index++)
{
// For each screen, add the screen properties to a list box.
   listBox1.Items.Add("Device Name: " + screens[index].DeviceName);
   listBox1.Items.Add("Bounds: " + screens[index].Bounds.ToString());
   listBox1.Items.Add("Type: " + screens[index].GetType().ToString());
   listBox1.Items.Add("Working Area: " + screens[index].WorkingArea.ToString());
   listBox1.Items.Add("Primary Screen: " + screens[index].Primary.ToString());
}
int索引;
int上界;
Screen[]screens=Screen.AllScreens;
上限=屏幕。GetUpperBound(0);

for(index=0;indexScreen类表示单个系统上的一个或多个显示设备。您应该需要分辨率的“Bounds”属性和连接的显示器数量的“AllScreens”属性

int index;
int upperBound; 
Screen [] screens = Screen.AllScreens;
upperBound = screens.GetUpperBound(0);
for(index = 0; index <= upperBound; index++)
{
// For each screen, add the screen properties to a list box.
   listBox1.Items.Add("Device Name: " + screens[index].DeviceName);
   listBox1.Items.Add("Bounds: " + screens[index].Bounds.ToString());
   listBox1.Items.Add("Type: " + screens[index].GetType().ToString());
   listBox1.Items.Add("Working Area: " + screens[index].WorkingArea.ToString());
   listBox1.Items.Add("Primary Screen: " + screens[index].Primary.ToString());
}
int索引;
int上界;
Screen[]screens=Screen.AllScreens;
上限=屏幕。GetUpperBound(0);

对于(index=0;index为什么您只担心监视器数量的减少?简单地降低单个监视器上的屏幕分辨率可能会导致恢复持久化窗口维度的问题。不同的屏幕分辨率不应该是WPF和窗口布局方式的问题。我们没有固定的pixel在任何地方都可以定位。为什么你只担心监视器数量的减少?简单地降低单个监视器上的屏幕分辨率可能会导致恢复持久化窗口维度的问题。不同的屏幕分辨率不应该是WPF和我们的窗口布局方式的问题。我们没有f任意位置的混合像素位置。