C# winform 雙屏顯示


 雙屏顯示1
// 利用WinForm中的Screen類,即可比較方便地實現多窗體分別在多個屏幕上顯示。
        //•獲取當前系統連接的屏幕數量: 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));
        //•讓窗體在第2個屏幕上顯示:
        //this.Left = ((Screen.AllScreens[1].Bounds.Width - this.Width) / 2);
        //this.Top = ((Screen.AllScreens[1].Bounds.Height - this.Height) / 2);
        private void showOnMonitor(int showOnMonitor)
        {
            Screen[] sc;
            sc = Screen.AllScreens;
            if (showOnMonitor >= sc.Length)
            {
                showOnMonitor = 0;
            }
            this.FormBorderStyle = FormBorderStyle.None; //無邊框全屏顯示
            this.StartPosition = FormStartPosition.Manual;
            this.Location = new Point(sc[showOnMonitor].Bounds.Left, sc[showOnMonitor].Bounds.Top);  
            //this.Location = new Point(((sc[showOnMonitor].Bounds.Width-this.Width)/2), ((sc[showOnMonitor].Bounds.Height-this.Height)/2));
            // If you intend the form to be maximized, change it to normal then maximized.               
            //this.WindowState = FormWindowState.Normal;
            this.WindowState = FormWindowState.Maximized;//最大化窗口

        }

如果接雙顯卡時showOnMonitor 參數等於0為主屏,1為擴展屏

 

 雙屏顯示2
 1  private void showOnMonitor2()
 2         {
 3             Screen[] sc;
 4             sc = Screen.AllScreens;
 5             //get all the screen width and heights 
 6             Form1 f = new Form1();
 7             f.FormBorderStyle = FormBorderStyle.None;
 8             f.Left = sc[1].Bounds.Width;
 9             f.Top = sc[1].Bounds.Height;
10             f.StartPosition = FormStartPosition.Manual;
11             f.Location = sc[1].Bounds.Location;
12             Point p = new Point(sc[1].Bounds.Location.X, sc[1].Bounds.Location.Y);
13             f.Location = p;
14             f.WindowState = FormWindowState.Maximized;
15             f.Show();
16         }
17 
18 接入雙顯卡時sc[0]為主屏、sc[1]擴展屏

 

一個窗體雙屏顯示
  this.Location = new Point(0,0);            
            Screen[] sc;
            sc = Screen.AllScreens;
            this.Width = (sc[0].Bounds.Width + sc[1].Bounds.Width);//+20;
            this.Height = (sc[0].Bounds.Height); //+200;
            this.FormBorderStyle = FormBorderStyle.None; //邊框樣式
            webBrowser1.Width = sc[0].Bounds.Width;
            webBrowser1.Height = sc[0].Bounds.Height;
            webBrowser1.Location = new Point(sc[0].Bounds.Location.X, sc[0].Bounds.Location.Y);            
            webBrowser1.Url = new Uri("http://www.google.com.hk");


            webBrowser2.Width = sc[1].Bounds.Width;
            webBrowser2.Height = sc[1].Bounds.Height;
            webBrowser2.Location = new Point(sc[1].Bounds.Location.X, sc[1].Bounds.Location.Y);
            webBrowser2.Url = new Uri("http://www.baidu.com");

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM