C#: Programmatically Get the Current DPI Setting

Frequently Windows 7 ships configured to use 120 DPI rather than the previously standard 96 DPI. For Windows Forms developers this can cause a few problems with the layout and appearance of forms. If you need to make changes programmatically depending on the current DPI setting, the first thing you will need to do is figure out what the DPI setting is at runtime. One way to do this is to create a Graphics object and check the DpiX or DpiY property as shown below.

int currentDPI = 0;

using (Graphics g = this.CreateGraphics())
    currentDPI = (int)g.DpiX;    

Once you get the current DPI setting (96, 120, 144, or 192) you can make the necessary changes to the appearance of your form.


4 Responses to “C#: Programmatically Get the Current DPI Setting”

  1. blah Says:

    nope, siree bob, this doean’t work. I have medium fondt size at 125% on W7 64bit, and still i get DpiX = 96…

    • Nick Olsen Says:

      I don’t know what to tell you. I just tested the code using Windows 7 64-bit on a profile set to the medium font size and I got currentDPI = 120. Maybe post your code for a second pair of eyes?

  2. Chris Says:

    For me it worked with the dpi set to 120 on Windows 7 64bit but when I went to 150% (144dpi) it started returning 96

    • sajidsrqsajid Says:

      how can we change programatically DPI 120 to 96 in c#.please help

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: