Finding the DPI size for items in VB.NET

  • Thread starter Thread starter Jason
  • Start date Start date
J

Jason

Hi everyone, there is some text in one of my VB.NET
programs (on a form of course) that looks outwright silly
if the users system is changed to 120 DPI. (This
particular setting is modified if you go to your Display
Properties, then select the Settings Tab, then select
Advanced, then in the Advanced properties, you select the
General Tab, and the first pull-down in the general tab
has DPI settings.

Is ther a windows system API call that one can use to
determine the DPI setting the users have selected in
windows so I can set up an IF statement in my form and
make it look good either way.

Thanks in advance to all those who reply.
 
* "Jason said:
Hi everyone, there is some text in one of my VB.NET
programs (on a form of course) that looks outwright silly
if the users system is changed to 120 DPI. (This
particular setting is modified if you go to your Display
Properties, then select the Settings Tab, then select
Advanced, then in the Advanced properties, you select the
General Tab, and the first pull-down in the general tab
has DPI settings.

Is ther a windows system API call that one can use to
determine the DPI setting the users have selected in

Untested, quick and dirty:

\\\
Private Declare Auto Function GetDesktopWindow Lib "user32.dll" ( _
) As IntPtr

Private Declare Auto Function GetDC Lib "user32.dll" ( _
ByVal hWnd As IntPtr _
) As IntPtr

Private Declare Auto Function GetDeviceCaps Lib "gdi32.dll" ( _
ByVal hdc As IntPtr, _
ByVal nIndex As Int32 _
) As Int32

Private Declare Auto Function ReleaseDC Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal hdc As IntPtr _
) As Int32

Private Function SmallFonts() As Boolean
Dim hWndDesktop As IntPtr, hDCDesktop As IntPtr
Dim PixelsX As Int32
hWndDesktop = GetDesktopWindow
hDCDesktop = GetDC(hWndDesktop)
PixelsX = GetDeviceCaps(hDCDesktop, 88)
ReleaseDC(hWndDesktop, hDCDesktop)
SmallFonts = (PixelsX = 96)
End Function
///

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

<http://www.plig.net/nnq/nquote.html>
 
Back
Top