我有一个使用Aero Glass的WPF应用程序。在120dpi设置下使用应用程序时,我的UI中的边距与我传递给DwmExtendFrameIntoClientArea API调用的边距不匹配。
如何在.NET 3.0中获取系统DPI设置,以便我可以更正传递给DwmExtendFrameIntoClientArea API调用的边距?
基本上,WPF UI使用与设备无关的单元,而DwmExtendFrameIntoClientArea API调用使用像素。
由于
答案 0 :(得分: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