How to get DPI in C# .NET?

前端 未结 1 608
迷失自我
迷失自我 2020-12-06 11:26

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

1条回答
  •  有刺的猬
    2020-12-06 12:23

    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();
    }
    

    0 讨论(0)
提交回复
热议问题