Determine system's dpi setting

G

Guest

Can somebody please tell me how to determine the system's dpi setting (e.g.,
96 dpi for normal size, 120 dpi for large size or some other value for custom
dpi).

Thanks,
Lance
 
S

Siva M

This is one way:

<DllImport("user32.dll")> _
Public Shared Function GetDC(ByVal hWnd As HandleRef) As IntPtr
End Function

<DllImport("gdi32.dll")> _
Public Shared Function GetDeviceCaps(ByVal hDC As IntPtr, ByVal nIndex As
Integer) As Integer
End Function

<DllImport("user32.dll")> _
Public Shared Function ReleaseDC(ByVal hWnd As IntPtr, ByVal hDC As IntPtr)
As Integer
End Function

dDC = GetDC(Nothing) ' Get desktop DC
dpi = GetDeviceCaps(dDC, 88)
MsgBox("DPI Value: " & dpi.ToString())
rv = ReleaseDC(Nothing, dDC)

Alternatively,

Dim dDC As IntPtr
Dim rv As Integer
Dim g As Graphics

dDC = GetDC(Nothing) 'Get desktop DC
g = Graphics.FromHdc(dDC)
MsgBox("DPI Value: " & g.DpiX.ToString())
g.Dispose()
rv = ReleaseDC(Nothing, dDC)

Yet another way, if you have a Windows form (Form1),

Dim g As Graphics

g = Graphics.FromHwnd (Form1.Handle)
MsgBox("DPI Value: " & g.DpiX.ToString())
g.Dispose()


Hope this helps?

Can somebody please tell me how to determine the system's dpi setting (e.g.,
96 dpi for normal size, 120 dpi for large size or some other value for
custom
dpi).

Thanks,
Lance
 
H

Herfried K. Wagner [MVP]

ljlevend2 said:
Can somebody please tell me how to determine the system's dpi setting
(e.g.,
96 dpi for normal size, 120 dpi for large size or some other value for
custom
dpi).

Create a 'Graphics' object for a form, for example, and check its 'DpiX' and
'DpiY' properties.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top