c# Winform 開發分屏顯示應用程式

來源:互聯網
上載者:User

標籤:

分屏顯示即可把一台主機內啟動並執行多個程式分別顯示在不同的兩個(或多個)螢幕上。目前市面上主流的顯卡都支援分屏顯示(顯示雙螢幕),如果需要顯示2個以上的螢幕,則應使用“拖機卡”類的硬體。

 

設定分屏顯示的兩種方法如下:

1、用兩個顯卡串連兩台顯示器,進入系統後,分清楚哪一個是主顯卡,在案頭空白處按右鍵,點屬性,然後在視窗中點“設定”選項卡,會看到有兩個顯示,分別是1(主顯卡)和2(副顯卡),點擊那個2,在下面的“將windows案頭擴充到該監視器”打上對號,確定後,你試著把滑鼠往主顯示器右邊界移動,再移動,滑鼠會跑到第二台顯示器上去了,這樣,同樣運行幾個程式,分別將它們的視窗拖拽到兩個顯示器的地區中就可以了,這實際上是將案頭擴充了一下。

2、使用專門的硬體。可以使用“一拖多”的拖機卡,只要將裝置插入usb口中,將裝置上引出的兩個ps/2口分別接滑鼠和鍵盤,主機中還是有兩塊顯卡,然後再裝上這個裝置的專用軟體,重啟後,經過簡單的配置,即可實現“完全”獨立的兩個系統。

 

所謂的分屏或多屏軟體,就是把軟體中的多個表單,在主畫面運行,但是把各個表單(座標)移動到各個擴充螢幕位置上如所示:

 

主畫面
(MainForm)
index=0
擴充螢幕1
(Form1)
index=1
擴充螢幕2
(Form2)
index=...
擴充螢幕3
(Form3)
index=...

 

 

以下介紹最常用的雙螢幕顯示,也就是左右模式的螢幕顯示的方法。

WinForm 的實現辦法:

利用WinForm中的Screen類,即可比較方便地實現多表單分別在多個螢幕上顯示。

 

  • 擷取當前系統串連的螢幕數量: Screen.AllScreens.Count();
  • 擷取當前螢幕的名稱:string CurrentScreenName = Screen.FromControl(this).DeviceName;
  • 擷取當前螢幕對象:Screen CurrentScreen = Screen.FromControl(this);
  • 擷取當前滑鼠所在的螢幕:Screen CurrentScreen = Screen.FromPoint(new Point(Cursor.Position.X, Cursor.Position.Y));
  • 讓表單在第2個螢幕上顯示:
     this.Left = ((Screen.AllScreens[1].Bounds.Width - this.Width) / 2);
     this.Top = ((Screen.AllScreens[1].Bounds.Height - this.Height) / 2); 把任何表單顯示在任何螢幕的方法:  [csharp] view plaincopy  
  1. //在表單的OnLoad事件中調用該方法  
  2. protected void Form1_OnLoad(...) {  
  3.     showOnMonitor(1);//index=1  
  4. }  
  5.   
  6. private void showOnMonitor(int showOnMonitor)   
  7. {   
  8.     Screen[] sc;   
  9.     sc = Screen.AllScreens;   
  10.     if (showOnMonitor >= sc.Length) {  
  11.         showOnMonitor = 0;  
  12.     }  
  13.   
  14.   
  15.     this.StartPosition = FormStartPosition.Manual;   
  16.     this.Location = new Point(sc[showOnMonitor].Bounds.Left, sc[showOnMonitor].Bounds.Top);  
  17.     // If you intend the form to be maximized, change it to normal then maximized.  
  18.     this.WindowState = FormWindowState.Normal;  
  19.     this.WindowState = FormWindowState.Maximized;  
  20. }  

對WPF表單來說,只要簡單的更改即可:首先要添加對 System.Windows.Forms 和 System.Drawing 的引用簡單的參考代碼如下: [csharp] view plaincopy  
  1. protected override void OnStartup(StartupEventArgs e)  
  2.         {  
  3.             base.OnStartup(e);  
  4.   
  5.             Window1 w1 = new Window1();  
  6.             Window2 w2 = new Window2();  
  7.   
  8.   
  9.             Screen s1 = Screen.AllScreens[0];  
  10.             Screen s2 = Screen.AllScreens[1];  
  11.   
  12.             Rectangle r1 = s1.WorkingArea;  
  13.             Rectangle r2 = s2.WorkingArea;  
  14.   
  15.             w1.Top = r1.Top;  
  16.             w1.Left = r1.Left;  
  17.   
  18.             w2.Top = r2.Top;  
  19.             w2.Left = r2.Left;  
  20.   
  21.             w1.Show();  
  22.             w2.Show();  
  23.   
  24.             w2.Owner = w1;  
  25.   
  26.   
  27.         }  
注意:一定應該在表單載入前,判斷所要顯示的螢幕是否存在,否則會報錯! 轉自:http://www.cnblogs.com/lizi/archive/2012/02/21/2361229.html

c# Winform 開發分屏顯示應用程式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.