Как приложение Multi Monitor может обнаружить отсутствующий монитор - PullRequest
1 голос
/ 12 марта 2012

Приложение с возможностью стыковки может сохранить рабочий стол с позициями всех окон, включая окна на отдельных мониторах.

Если сохраненный рабочий стол перезагружается, но один или несколько мониторов не подключены, приложениедолжен обнаружить это.У меня есть следующее:

    ...
    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;
   }

Проблема в том, что этот метод не определяет, больше ли недоступен монитор, но находится ли область за пределами области главного окна.

Кто-нибудьзнаете, как обнаружить отключенный монитор или недоступную область?

1 Ответ

1 голос
/ 12 марта 2012

Класс экрана представляет устройство отображения или несколько устройств отображения в одной системе. Вам необходимо указать атрибут «Границы» для разрешений и атрибут «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());
}

Подробнее здесь: http://msdn.microsoft.com/en-us/library/system.windows.forms.screen.aspx

...