code_junkie

WPF Aero Glass DPI Setting Mismatch

Nov 13th, 2011
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. 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
  2. '
  3. Dim Graphics As System.Drawing.Graphics = System.Drawing.Graphics.FromHwnd(WindowHandle)
  4. Dim DesktopDPIx As Single = Graphics.DpiX
  5. Dim DesktopDPIy As Single = Graphics.DpiY
  6.  
  7. Dim Margins As Margins = New Margins
  8. Margins.Left = Left * (DesktopDPIx / 96)
  9. Margins.Right = Right * (DesktopDPIx / 96)
  10. Margins.Top = Top * (DesktopDPIx / 96)
  11. Margins.Bottom = Bottom * (DesktopDPIx / 96)
  12. Return Margins
  13. '
  14. End Function
Add Comment
Please, Sign In to add comment