做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;