C#获取屏幕工作区大小

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

 

posted @ 2019-08-21 18:20  stonemqy  阅读(3515)  评论(0编辑  收藏  举报