Winform窗口实现多显示屏显示的2种方法
程序员文章站
2023-11-06 21:10:16
一台主机连接了2台显示器(2个显卡),要求一个程序的两个窗体在不同的显示器上显示:显示器1 显示from1,显示器2 显示from2。代码及说明如下:
f...
一台主机连接了2台显示器(2个显卡),要求一个程序的两个窗体在不同的显示器上显示:显示器1 显示from1,显示器2 显示from2。代码及说明如下:
form1不需要变更代码,from2添加如下代码:
// 方法一: from2 frm2 = new from2(); if (screen.allscreens.count() != 1) { frm2.left = screen.allscreens[0].bounds.width; frm2.top = 0; frm2.size = new system.drawing.size(screen.allscreens[1].bounds.width, screen.allscreens[1].bounds.height); } // 方法二: this.left = ((screen.allscreens[1].bounds.width - this.width) / 2); this.top = ((screen.allscreens[1].bounds.height - this.height) / 2); this.size = new system.drawing.size(screen.allscreens[1].bounds.width, screen.allscreens[1].bounds.height);
说明:
获取当前系统连接的屏幕数量: 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));