分屏显示即可把一台主机内运行的多个程序分别显示在不同的两个(或多个)屏幕上。目前市面上主流的显卡都支持分屏显示(显示双屏幕),如果需要显示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;
- }
出处:https://www.cnblogs.com/lizi/archive/2012/02/21/2361229.html
================================================================
通过C#判断Screen.AllScreens的数量,然后确认有副屏幕。
把界面显示在副屏,再通过事件发布订阅来传递信息彼此之间的信息。
//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;
出处:https://bbs.csdn.net/topics/392194646
================================================================
自己写的
public partial class FormChild : Form { private int showAtScreenNum = 0; private bool isShowVideo = false; public FormChild () { InitializeComponent(); Load += FormChild _Load; this.FormClosing += FormChild _FormClosing; } private void FormChild _FormClosing(object sender, FormClosingEventArgs e) { isShowVideo = false; } private void FormChild _Load(object sender, EventArgs e) { //VideoFrameTransfer.Instance.VideoFrameArrived += Instance_VideoFrameArrived; 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[0].Bounds.Width; this.Top = 0; 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].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 VideoFrameArrived(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 FormChild _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; } } }