Q:

DPI Graphics Screen Resolution Pixels WinForm PrintPageEventArgs

How do Dpi Points relate to Pixels for any display my application is running on?
int points;
Screen primary;

public Form1() {
  InitializeComponent();
  points = -1;
  primary = null;
}

void OnPaint(object sender, PaintEventArgs e) {
  if (points < 0) {
    points = (int)(e.Graphics.DpiX / 72.0F); // There are 72 points per inch
  }
  if (primary == null) {
    primary = Screen.PrimaryScreen;
    Console.WriteLine(primary.WorkingArea.Height);
    Console.WriteLine(primary.WorkingArea.Width);
    Console.WriteLine(primary.BitsPerPixel);
  }
}

Do I now have all of the information I need?
Can I use any of the information above to find out just how long 1200 pixels is?

A:

DPI literally stands for "Dots Per Inch" - where dots==pixels.  So to determine how long 1200 pixels is:
int inchesLong = (1200 / e.Graphics.DpiX);

A:

I realize it has been a few months, but while reading a book on WPF, I came across the answer:
If using standard Windows DPI setting (96 dpi), each device-independent unit corresponds to one real, physical pixel.
[Physical Unit Size] = [Device-Independent Unit Size] x [System DPI]
                     = 1/96 inch x 96 dpi
                     = 1 pixel

Hence, 96 pixels to make an inch through the Windows system DPI settings.
However, this does, in reality, depend on your display size.
For a 19-inch LDC monitor set to a resolution of 1600 x 1200, use the Pythagoras theorem helps to calculate pixel density for the monitor:
[Screen DPI] = Math.Sqrt(Math.Pow(1600, 2) + Math.Pow(1200, 2)) / 19

Using this data, I wrote up a little static tool that I now keep in my Tools class of all my projects:
/// <summary>
/// Calculates the Screen Dots Per Inch of a Display Monitor
/// </summary>
/// <param name="monitorSize">Size, in inches</param>
/// <param name="resolutionWidth">width resolution, in pixels</param>
/// <param name="resolutionHeight">height resolution, in pixels</param>
/// <returns>double presision value indicating the Screen Dots Per Inch</returns>
public static double ScreenDPI(int monitorSize, int resolutionWidth, int resolutionHeight) {
  //int resolutionWidth = 1600;
  //int resolutionHeight = 1200;
  //int monitorSize = 19;
  if (0 < monitorSize) {
    double screenDpi = Math.Sqrt(Math.Pow(resolutionWidth, 2) + Math.Pow(resolutionHeight, 2)) / monitorSize;
    return screenDpi;
  }
  return 0;
}

I hope others get some use out of this nifty little tool.

