分屏顯示即可把一台主機內運行的多個程序分別顯示在不同的兩個(或多個)屏幕上。目前市面上主流的顯卡都支持分屏顯示(顯示雙屏幕),如果需要顯示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);
this.Top = ((Screen.AllScreens[1].Bounds.Height - this.Height) / 2);
把任何窗體顯示在任何屏幕的方法:
- //在窗體的OnLoad事件中調用該方法
- protected void Form1_OnLoad(...) {
- showOnMonitor(1);//index=1
- }
- private void showOnMonitor(int showOnMonitor)
- {
- Screen[] sc;
- sc = Screen.AllScreens;
- if (showOnMonitor >= sc.Length) {
- showOnMonitor = 0;
- }
- this.StartPosition = FormStartPosition.Manual;
- this.Location = new Point(sc[showOnMonitor].Bounds.Left, sc[showOnMonitor].Bounds.Top);
- // If you intend the form to be maximized, change it to normal then maximized.
- this.WindowState = FormWindowState.Normal;
- this.WindowState = FormWindowState.Maximized;
- }
對WPF窗體來說,只要簡單的更改即可:
首先要添加對 System.Windows.Forms
和 System.Drawing 的引用
簡單的參考代碼如下:
- protected override void OnStartup(StartupEventArgs e)
- {
- base.OnStartup(e);
- Window1 w1 = new Window1();
- Window2 w2 = new Window2();
- Screen s1 = Screen.AllScreens[0];
- Screen s2 = Screen.AllScreens[1];
- Rectangle r1 = s1.WorkingArea;
- Rectangle r2 = s2.WorkingArea;
- w1.Top = r1.Top;
- w1.Left = r1.Left;
- w2.Top = r2.Top;
- w2.Left = r2.Left;
- w1.Show();
- w2.Show();
- w2.Owner = w1;
- }
注意:一定應該在窗體加載前,判斷所要顯示的屏幕是否存在,否則會報錯!