分屏顯示即可把一臺主機內運行的多個程序分別顯示在不同的兩個(或多個)屏幕上。目前市面上主流的顯卡都支持分屏顯示(顯示雙屏幕),如果需要顯示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.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窗體來說,只要簡單的更改即可:
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;
}