Click here to Skip to main content
Click here to Skip to main content

Tagged as

Go to top

Device Independent Units to Points to Inches

, 5 Nov 2009
Rate this:
Please Sign up or sign in to vote.
The default unit of measurement in Windows Forms was pixels. This worked well when most monitors on the market used a simple 96 pixel per inch measurement, but measuring by pixel causes problems when working with devices that have different resolutions.

The default unit of measurement in Windows Forms was pixels. This worked well when most monitors on the market used a simple 96 pixel per inch measurement, but measuring by pixel causes problems when working with devices that have different resolutions. For example, with Windows Forms, a 100 pixel button would appear to be about an inch wide on a 96 pixel/inch monitor. However, on a 120 pixel/inch monitor, the same button would appear to be 4/5 of an inch. A 160 pixel/inch monitor would show the button as 5/8 of an inch. And on a 60 pixel/inch screen, the button would appear to be about 1 2/3 inches wide.

With the introduction of WPF, Microsoft began using DIU (Device Independent Units). A DIU (also known as a Device Independent Pixel, or DIP) measurement is based on inches rather than hardware-specific pixels. A DIU is defined as 1/96 of an inch (smaller than the point, which is defined as 1/72 of an inch). For a standard 96 pixel per inch monitor, 96 DIU = 96 pixels. For monitors with 120 pixels/inch, 96 DIU = 120 pixels. For a monitor with 60 pixels/inch, 10 DIU = 60 pixels. When the measurement doesn't work out to a perfectly round number (as is often the case), WPF will automatically use anti-aliasing, or you have the option of “snapping” to the nearest pixel if you don't want "fuzzy" outlines for your button, etc.

One kink is that all measurements, including text, are now measured in DIU. In Windows Forms, depending on what control you were using, font size was often measured in points (a point is 1/72 of an inch and is the measurement used in Word and other applications). So now when you specify font size 12, you are actually specifying a 9 point font (which is probably smaller than you intended).

To help with this transition, I've put together a quick chart to quickly convert inches and points into DIU. I hope this helps:

Units of Measurement

Inches

Points

DIU

1/96 3/4 1
1/72 1 1 1/3
1/48 1 1/2 2
1/32 2 1/4 3
1/24 3 4
1/16 4 1/2 6
1/12 6 8
1/8 9 12
5/36 10 13 1/3
1/6 12 16
3/16 13 1/2 18
1/4 18 24
1/3 24 32
1/2 36 48
3/4 54 72
1 72 96
1 1/2 108 144
2 144 192
3 216 288
4 288 384
5 360 480
8 576 768
10 720 960
11 1/2 828 1104
12 864 1152

* 'Device-Independent Units' (DIU) are also called 'Device-Independent Pixels' (DIP)

View on

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Cyborgx37
Software Developer (Senior)
United States United States
No Biography provided
Follow on   Google+

Comments and Discussions

 
GeneralMy vote of 5 PinmemberRod Falanga4-Apr-13 11:01 
GeneralMy vote of 4 PinmemberAndru Martin21-Feb-11 21:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 5 Nov 2009
Article Copyright 2009 by Cyborgx37
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid