Winform窗口實(shí)現(xiàn)多顯示屏顯示的2種方法
一臺(tái)主機(jī)連接了2臺(tái)顯示器(2個(gè)顯卡),要求一個(gè)程序的兩個(gè)窗體在不同的顯示器上顯示:顯示器1 顯示From1,顯示器2 顯示From2。代碼及說(shuō)明如下:
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);
說(shuō)明:
獲取當(dāng)前系統(tǒng)連接的屏幕數(shù)量: Screen.AllScreens.Count();
獲取當(dāng)前屏幕的名稱(chēng):string CurrentScreenName = Screen.FromControl(this).DeviceName;
獲取當(dāng)前屏幕對(duì)象:Screen CurrentScreen = Screen.FromControl(this);
獲取當(dāng)前鼠標(biāo)所在的屏幕:Screen CurrentScreen = Screen.FromPoint(new Point(Cursor.Position.X, Cursor.Position.Y));
相關(guān)文章
c#實(shí)現(xiàn)16進(jìn)制和字符串之間轉(zhuǎn)換的代碼
#中十六進(jìn)制字符串的轉(zhuǎn)換函數(shù)2007-05-05

