【发布时间】:2016-03-12 21:49:10
【问题描述】:
我刚刚编写了一个简单的 PowerShell 脚本来获取显示器的屏幕分辨率,但它似乎返回了错误的值。
# Returns an screen width and screen height of maximum screen resolution
function Get-ScreenSize {
$screen = [System.Windows.Forms.Screen]::PrimaryScreen
$width = $screen.Bounds.Width
$height = $screen.Bounds.Height
return $width, $height
}
Get-ScreenSize
我在分辨率设置为 3840 x 2160 的 4k 显示器上运行此脚本,但它给了我以下输出:
1536
864
有什么会导致System.Windows.Forms.Screen 得到错误的“Bounds”值吗?
【问题讨论】:
-
当使用WorkingArea 而不是Bounds 属性时,您会得到什么值?
-
我得到 3840 x 2060 非常接近,但仍然不太正确。
-
看起来是正确的。全宽,全高减去任务栏。
-
好的,嗯,那我想知道为什么 bounds 返回了错误的值...
-
查看Screen 的参考实现,看起来
Bounds使用虚拟屏幕大小(虽然不完全确定,为什么数字小于预期),而WorkingArea使用多显示器 API。不过,我不知道如何修复 PowerShell commandlet。
标签: winforms powershell winapi screen-resolution