Incorrect DPI setting of WPF Aero Glass

I have a WPF application using Aero Glass. When using the application under the 120dpi setting, the fields in my user interface do not match the fields that I pass to the DwmExtendFrameIntoClientArea API call.

How to get the system DPI parameter in .NET 3.0 so that I can fix the field that I pass to the DwmExtendFrameIntoClientArea API call?

Essentially, the WPF user interface uses device-independent units, while the DwmExtendFrameIntoClientArea API call uses pixels.

thanks

+3
source share
1 answer

Well, something like the following will fix the problem:

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



: Pro WPF # 2008

+4

All Articles