做Winform或WPF程序時,有時需要獲取當前系統屏幕的大小(含任務欄或不含任務欄),具體方法如下:
1. 引入System.Windows.Forms命名空間;
2. 獲取含任務欄的屏幕大小:
var h = Screen.PrimaryScreen.Bounds.Height; var w = Screen.PrimaryScreen.Bounds.Width;
3. 獲取不含任務欄的屏幕大小:
var h = SystemInformation.WorkingArea.Height; var w = SystemInformation.WorkingArea.Width;