3

我有一个使用 Aero Glass 的 WPF 应用程序。在 120dpi 设置下使用应用程序时,我的 UI 中的边距与我传递给 DwmExtendFrameIntoClientArea API 调用的边距不匹配。

如何在 .NET 3.0 中获取系统 DPI 设置,以便更正传递给 DwmExtendFrameIntoClientArea API 调用的边距?

本质上,WPF UI 使用与设备无关的单位,而 DwmExtendFrameIntoClientArea API 调用使用像素。

谢谢

4

1 回答 1

4

好的,类似以下内容将解决此问题:

Public Shared Function GetDpiAdjustedMargins(ByVal WindowHandle As IntPtr, ByVal Left As Integer, ByVal Right As Integer, ByVal Top As Integer, ByVal Bottom As Integer) As Margins
    '
    Dim Graphics As System.Drawing.Graphics = System.Drawing.Graphics.FromHwnd(WindowHandle)
    Dim DesktopDPIx As Single = Graphics.DpiX
    Dim DesktopDPIy As Single = Graphics.DpiY

    Dim Margins As Margins = New Margins
    Margins.Left = Left * (DesktopDPIx / 96)
    Margins.Right = Right * (DesktopDPIx / 96)
    Margins.Top = Top * (DesktopDPIx / 96)
    Margins.Bottom = Bottom * (DesktopDPIx / 96)
    Return Margins
    '
End Function



资料来源:C# 2008 中的 Pro WPF,作者:Matthew MacDonald

于 2009-01-13T07:43:24.207 回答