Winform窗口實現(xiàn)多顯示屏顯示的2種方法
一臺主機連接了2臺顯示器(2個顯卡),要求一個程序的兩個窗體在不同的顯示器上顯示:顯示器1 顯示From1,顯示器2 顯示From2。代碼及說明如下:
Form1不需要變更代碼,F(xiàn)rom2添加如下代碼:
// 方法一:
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);
說明:
獲取當前系統(tǒng)連接的屏幕數(shù)量: 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));
相關文章
c#實現(xiàn)16進制和字符串之間轉(zhuǎn)換的代碼
#中十六進制字符串的轉(zhuǎn)換函數(shù)2007-05-05

