Winform窗口實現多顯示屏顯示的2種方法,本文直接給出了實現代碼,並對其中的一些重要參數作了解釋,須要的朋友能夠參考下。this
一臺主機鏈接了2臺顯示器(2個顯卡),要求一個程序的兩個窗體在不一樣的顯示器上顯示:顯示器1 顯示From1,顯示器2 顯示From2。代碼及說明以下:spa
Form1不須要變動代碼,From2添加以下代碼:code
// 方法一: 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);
說明:orm
獲取當前系統鏈接的屏幕數量: Screen.AllScreens.Count();對象
獲取當前屏幕的名稱:string CurrentScreenName = Screen.FromControl(this).DeviceName;blog
獲取當前屏幕對象:Screen CurrentScreen = Screen.FromControl(this);string
獲取當前鼠標所在的屏幕:Screen CurrentScreen = Screen.FromPoint(new Point(Cursor.Position.X, Cursor.Position.Y));it