DPI Settings

J

Jeff

Hi -

I have a VB.NET application (for Win2K and later), and I'd like to ensure
that it displays properly regardless of how the user has set his DPI Setting
on his system.

1. What is the best way to detect the user's DPI setting?

I found 2 registry keys, but which is the right one to check (or is there a
better way)? The 2 keys I found are:

HKCU\Control Panel\Desktop\WindowsMetrics\AppliedDPI
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontDPI\LogPixels

I'm guessing, if checking the registry is the best approach, that the
LogPixels value is the one to check. (I've read somewhere that AppliedDPI
may not be present for all Windows versions.)

2. What is the best way to code my application to accommodate different DPI
settings?

I could 'brute-force' it by coditionally setting top/right/bottom/left for
each control, depending on the result from my question 1 (above). That
would seem to be a lot of work, would expand code size, and might affect
performance. (And it doesn't address possible custom settings.) Is there a
better way?

How are all of you handling this issue?

Thanks for your help.

- Jeff
 
N

Nak

Hi Jeff,

I think you can use the graphics object for the form or control,

Dim pop As Graphics = Me.CreateGraphics
Console.WriteLine(pop.DpiX & " - " & pop.DpiY)

Nick.
 
J

Jeff

Thanks Nick -

As I understand your suggestion, it's an alternate way to detect the dpi
setting. Why/how is it better than checking the registry settings? And
again, how should I code my application to accommodate different DPI
settings?

- Jeff
 
N

Nak

Hi Jeff,
As I understand your suggestion, it's an alternate way to detect the dpi
setting. Why/how is it better than checking the registry settings? And
again, how should I code my application to accommodate different DPI
settings?

I believe that the graphics context for a form would have to be made at
the current systems DPI settings by default. There isn't any particular
reason why it should be better than checking the registry but I believe it
to always be better to use another method other than a hard coded registry
key. I'm sure there must also be an API available (which is always the
preferred choice).

http://www.mentalis.org/apilist/GetDeviceCaps.shtml
^Apparently *all* versions of Windows support this!

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dngdi/html/highdpiapp.asp
^An MSDN article on the subject!

As to how you would program an application to accommodate a different
DPI, I have no idea! Though the above MSDN link shows you how. It's
interesting you should ask this question because I have never thought of it
before, and I certainly remember applications like Dreamweaver being
tempramental in the past due to high DPI incompatability.

Anyway, I hope this information is helpful!

Nick.
 

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