Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get DPI in C# .NET?

I'm trying to build a Windows Forms application using C#.

How do I get the DPI in .NET?

I've read before that there is DPIX and DPIY, which can be used in .NET to get the current DPI.

Is that correct?

Thanks all.

like image 586
Learn Programming Avatar asked Jul 27 '11 12:07

Learn Programming


1 Answers

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();
}
like image 159
Thorsten Dittmar Avatar answered Sep 22 '22 00:09

Thorsten Dittmar