Winform窗口實現多顯示屏顯示的2種方法
一臺主機連接了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);
說明:
獲取當前系統(tǒng)連接的屏幕數量: 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中寫app.config文件時調試情況下沒有改變的原因
讀取很簡單基本都用過 ConfigurationManager.AppSettings[""].ToString() 寫config不是很常用2013-02-02