VB.net - Windows.Forms.Screen.AllScreens报告错误的绑定大小使用任何DPI扩展超过125%,无论如何解决这个问题?

时间:2017-08-13 17:50:55

标签: vb.net vb.net-2010 dpi

我有我的vb.net应用程序(用VS2010 pro编写)设置,以检测和支持各种DPI缩放的多显示器设置。

我使用Screen.AllScreens.Length来了解我运行了多少台显示器:

Public Function getMonitorCount() As Integer
    Return Screen.AllScreens.Length
End Function

然后我遍历所有监视器以获取各种信息:

Public Sub getMonitorSetupFull()
    m = getMonitorCount()
    n = 0
    Do While n < m
        Monitor(n) = Windows.Forms.Screen.AllScreens(n)
        XLeft(n) = Monitor(n).Bounds.X
        YTop(n) = Monitor(n).Bounds.Y
        XRight(n) = XLeft(n) + Monitor(n).Bounds.Width
        YBottom(n) = YTop(n) + Monitor(n).Bounds.Height
        MonitorSize(n) = New Size(Monitor(n).Bounds.Width, Monitor(n).Bounds.Height)
        n = n + 1
    Loop
End Sub

我有一个问题,Monitor(n).Bounds(又名Windows.Forms.Screen.AllScreens(n).Bounds)在高DPI时给出了错误的值。例如,200%DPI Monitor(n).Bounds.Height给我一个值为540的1080p显示器(正好是一半)。在100%/ 125%DPI时,我得到1080这是正确的但是在126%DPI时我得到857而不是1080.

我是否可以添加到我的代码中以获取Windows.Forms.Screen.AllScreens(n).Bound来检测这些DPI的正确大小,或者我应该通过线路上的某些东西手动补偿这种偏心行为如果DPI> 125%,Windows.Forms.Screen.AllScreens(n).Bounds.Height = Windows.Forms.Screen.AllScreens(n).Bounds.Height * DPIratio?

更新:为了更加混淆这个问题,我发现如果我在设置DPI时选择使用Windows XP DPI缩放,则不会发生此问题。当我不使用Aero时也不会发生这种情况。我在其他Windows 7计算机上重现了这一点。

0 个答案:

没有答案