分屏顯示便可把一臺主機內運行的多個程序分別顯示在不一樣的兩個(或多個)屏幕上。目前市面上主流的顯卡都支持分屏顯示(顯示雙屏幕),若是須要顯示2個以上的屏幕,則應使用「拖機卡」類的硬件。html
設置分屏顯示的兩種方法以下:windows
一、用兩個顯卡鏈接兩臺顯示器,進入系統後,分清楚哪個是主顯卡,在桌面空白處右鍵單擊,點屬性,而後在窗口中點「設置」選項卡,會看到有兩個顯示,分別是1(主顯卡)和2(副顯卡),點擊那個2,在下面的「將windows桌面擴展到該監視器」打上對號,肯定後,你試着把鼠標往主顯示器右邊界移動,再移動,鼠標會跑到第二臺顯示器上去了,這樣,一樣運行幾個程序,分別將它們的窗口拖拽到兩個顯示器的區域中就能夠了,這其實是將桌面擴展了一下。app
二、使用專門的硬件。可使用「一拖多」的拖機卡,只要將設備插入usb口中,將設備上引出的兩個ps/2口分別接鼠標和鍵盤,主機中仍是有兩塊顯卡,而後再裝上這個設備的專用軟件,重啓後,通過簡單的配置,便可實現「徹底」獨立的兩個系統。ide
所謂的分屏或多屏軟件,就是把軟件中的多個窗體,在主屏幕運行,可是把各個窗體(座標)移動到各個擴展屏幕位置上以下圖所示:函數
主屏幕 (MainForm) index=0 |
擴展屏幕1 (Form1) index=1 |
擴展屏幕2 (Form2) index=... |
擴展屏幕3 (Form3) index=... |
如下介紹最經常使用的雙屏幕顯示,也就是左右模式的屏幕顯示的方法。oop
WinForm 的實現辦法:post
利用WinForm中的Screen類,便可比較方便地實現多窗體分別在多個屏幕上顯示。ui
- 獲取當前系統鏈接的屏幕數量: 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個屏幕上居中顯示:
在窗體的OnLoad事件中,插入以下代碼:
this.Left = ((Screen.AllScreens[1].Bounds.Width - this.Width) / 2);
this.Top = ((Screen.AllScreens[1].Bounds.Height - this.Height) / 2);
把任何窗體顯示在任何屏幕的方法:
-
- protected void Form1_OnLoad(...) {
- showOnMonitor(1);
- }
-
- private void showOnMonitor(int showOnMonitor)
- {
- Screen[] sc;
- sc = Screen.AllScreens;
- if (showOnMonitor >= sc.Length) {
- showOnMonitor = 0;
- }
-
-
- this.StartPosition = FormStartPosition.Manual; // 窗體的位置由 System.Windows.Forms.Control.Location 屬性指定
- this.Location = new Point(sc[showOnMonitor].Bounds.Left, sc[showOnMonitor].Bounds.Top);
-
- 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;
}
注意:必定應該在窗體加載前,判斷所要顯示的屏幕是否存在,不然會報錯!
//smartPartInfo是窗口類的實例
smartPartInfo.StartPosition = FormStartPosition.Manual;
smartPartInfo.Location = new Point(screens[1].Bounds.Left, screens[1].Bounds.Top);
smartPartInfo.Width = screens[1].Bounds.Width;
smartPartInfo.Height = screens[1].Bounds.Height;
public partial class FromChild : Form
{
private int showAtScreenNum = 0;
private bool isShowVideo = false;
public FromChild()
{
InitializeComponent();
Load += FromChild_Load;
this.FormClosing += FromChild_FormClosing;
}
private void FromChild_FormClosing(object sender, FormClosingEventArgs e)
{
isShowVideo = false;
}
private void FromChild_Load(object sender, EventArgs e)
{
label1.Parent = pictureBox1;
label1.BackColor = Color.Transparent;
if (Screen.AllScreens.Count() != 1)
{
SetChildScreen();
}
isShowVideo = true;
}
private void SetChildScreen()
{
showAtScreenNum = 1;
var screens = Screen.AllScreens;
this.Left = screens[1].Bounds.Left;
this.Top = screens[1].Bounds.Top;
this.StartPosition = FormStartPosition.Manual;
this.Location = new Point(screens[1].Bounds.Left, screens[1].Bounds.Top);
this.Width = screens[1].Bounds.Width;
this.Height = screens[1].Bounds.Height;
//this.Size = new System.Drawing.Size(screens[1].WorkingArea.Width, screens[1].WorkingArea.Height);
//this.Size = new System.Drawing.Size(screens[1].Bounds.Width + 20, screens[1].Bounds.Height + 40);
this.WindowState = FormWindowState.Maximized;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
}
/// <summary>
/// 接收視頻幀數據
/// </summary>
/// <param name="img"></param>
public void OnShowNewFrame(byte[] img)
{
if (isShowVideo)
ShowImage(img);
}
private void ShowImage(byte[] img)
{
if (pictureBox1.InvokeRequired)
{
this.BeginInvoke(new Action(() => ShowImage(img)));
}
else
{
pictureBox1.Image?.Dispose();
pictureBox1.Image = Image.FromStream(new MemoryStream(img));
}
}
const int WM_SYSCOMMAND = 0x112;
const int SC_MAXIMIZE = 0xF030;
const int SC_MAXIMIZE_DOUBLECLICK = 0xF012;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_SYSCOMMAND)
{
if (m.WParam.ToInt32() == SC_MAXIMIZE && Screen.AllScreens.Count() != 1)
SetChildScreen();
}
base.WndProc(ref m);
}
private void FromChild_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape && showAtScreenNum == 1)
{
showAtScreenNum = 0;
this.Left = 0;
this.Top = 0;
this.Size = new System.Drawing.Size(640, 480);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
this.WindowState = FormWindowState.Normal;
}
}
}
View Code