Winform窗話柄現多顯示屏顯示的2種辦法。本站提示廣大學習愛好者:(Winform窗話柄現多顯示屏顯示的2種辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是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);
解釋:
獲得以後體系銜接的屏幕數目: 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));