2012-03-12 8 views
1

ドッキング機能を備えたアプリケーションでは、デスクトップを別のモニタ上のウィンドウを含むすべてのウィンドウの位置に保存できます。マルチモニタアプリケーションが欠落しているモニタを検出する方法

保存されたデスクトップが再読み込みされても、1つ以上のモニタが接続されていない場合、アプリケーションはこれを検出する必要があります。

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

問題は、この方法では、モニターが使用できなくなったかどうかを検出しませんということですが、エリア外メイン・ウィンドウ領域のであるかどうか: は、私は次のよう持っています。

接続されていないモニタや使用できなくなった領域を検出する方法はありますか?

+0

なぜ数の減少についてあなたが唯一心配していますモニター?単一のモニターで画面の解像度を下げるなどの単純なことは、永続化されたウィンドウのサイズの復元に問題を引き起こす可能性があります。 –

+0

WPFとウィンドウをレイアウトする方法では、異なる画面解像度が問題になるはずはありません。固定ピクセル位置はどこにもありません。 – tobre

答えて

1

スクリーンクラスは、1つのシステム上のディスプレイデバイスまたは複数のディスプレイデバイスを表します。あなたは解像度のための「境界」属性と接続されているディスプレイの数のための「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