How to get DPI in C# .NET?

Use an instance of the Graphics class. You get this using the following within your form (could be in form’s Load event handler):

float dx, dy;

Graphics g = this.CreateGraphics();
try
{
    dx = g.DpiX;
    dy = g.DpiY;
}
finally
{
    g.Dispose();
}

Leave a Comment