您现在的位置是:网站首页> C#技术
C#多屏显示方法
- C#技术
- 2022-06-04
- 1376人已阅读
使用SetWindowPos设置位置
用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));
Winform下,不需要任何引用直接添加代码,这两行代码表示将一个无边框的窗体全屏显示在第二个窗体上。
this.FormBorderStyle = FormBorderStyle.None;
this.DesktopBounds = Screen.AllScreens[1].Bounds;
获取所有窗体的显示比率:
Screen[] s = Screen.AllScreens;
ScreensRect = new Rectangle[s.Length];
for (int i = 0; i < s.Length; i++)
{
ScreensRect[i] = s[i].WorkingArea;
}
获取第二屏的坐标:
int iX = ScreensRect[1].X;
int iY = ScreensRect[1].Y;
获取当前系统连接的屏幕数量:
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);
NET(C#)多屏(双屏)设置屏幕显示器分辨率方法代码(SetRes)
1、SetRes下载
下载地址:https://www.softpedia.com/get/Multimedia/Video/Other-VIDEO-Tools/Ian-Sharpe-SetRes.shtml
2、修改单屏代码
将下载的SetRes.exe拷到当前目录即可
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/c setres h1920 v1080";
process.StartInfo = startInfo;
process.Start();
3、修改双屏代码
将下载的SetRes.exe拷到当前目录即可
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/c SETRES m0:0 h1366 v768 && SETRES m1:0 h1280 v800";
process.StartInfo = startInfo;
process.Start();