分屏显示便可把一台主机内运行的多个程序分别显示在不一样的两个(或多个)屏幕上。目前市面上主流的显卡都支持分屏显示(显示双屏幕),若是须要显示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