2015-11-17 35 views
0

以下是簡化代碼,奇怪的是窗口停留在第二臺顯示器上,然後返回到第一臺主顯示器。必須有一個窗口設置或外部程序導致它。因爲相同的代碼在具有雙屏幕的另一臺計算機中工作。我確信並且再次檢查第二臺顯示器在索引1中:showOnMonitor(1,Q);c#:窗口轉到第二臺顯示器,然後跳回到主顯示器

Q = new queue(); 
showOnMonitor(1, Q); 
Q.Show(); 

public static void showOnMonitor(int monitor, Window w2) 
     { 
      Screen[] sc; 
      sc = Screen.AllScreens; 

      if (monitor >= sc.Length) 
      { 
       monitor = 0; 
      } 


      w2.WindowStartupLocation = WindowStartupLocation.Manual; 

      var workingArea = sc[monitor].WorkingArea; 
      w2.Left = workingArea.Left; 
      w2.Top = workingArea.Top; 
      w2.Width = workingArea.Width; 
      w2.Height = workingArea.Height; 

     } 
+0

打破調試showOnMonitor可以告訴你爲什麼..你試圖打破它嗎? – tgpdyk

+0

好主意,我會嘗試。 – William

+0

@tagaPdyk奇怪的是,一步一步地使用調試模式,窗口進入第二臺顯示器,而不會跳回第一臺顯示器,甚至直到執行結束。 – William

回答

0

好吧,我不知道爲什麼這個工程。但這是解決方案。

Q = new queue(); 
Q.Show(); 
Thread.Sleep(100); //need to delay first before moving the position 
showOnMonitor(1, Q); 

public static void showOnMonitor(int monitor, Window w2) 
     { 
      Screen[] sc; 
      sc = Screen.AllScreens; 

      if (monitor >= sc.Length) 
      { 
       monitor = 0; 
      } 


      w2.WindowStartupLocation = WindowStartupLocation.Manual; 

      var workingArea = sc[monitor].WorkingArea; 
      w2.Left = workingArea.Left; 
      w2.Top = workingArea.Top; 
      w2.Width = workingArea.Width; 
      w2.Height = workingArea.Height; 

     } 
相關問題