標籤:
分屏顯示即可把一台主機內啟動並執行多個程式分別顯示在不同的兩個(或多個)螢幕上。目前市面上主流的顯卡都支援分屏顯示(顯示雙螢幕),如果需要顯示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
- //在表單的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 的引用簡單的參考代碼如下:
[csharp] view plaincopy
- 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;
-
-
- }
注意:一定應該在表單載入前,判斷所要顯示的螢幕是否存在,否則會報錯! 轉自:http://www.cnblogs.com/lizi/archive/2012/02/21/2361229.html
c# Winform 開發分屏顯示應用程式