Search code examples
c#windowsdpi

How to get Windows Display settings?


There is setting for Display in Windows 7 (Control Panel -> Display). It allows to change the size of the text and other items on the screen. I need to get this setting to be able to switch on/switch off some functionality in my C# application based on the setting value. Is that possible?


Solution

  • This setting is the screen DPI, or dots per inch.

    Read it like so:

    float dpiX, dpiY;
    Graphics graphics = this.CreateGraphics();
    dpiX = graphics.DpiX;
    dpiY = graphics.DpiY;
    

    I don't think it's possible at the moment for the X and Y values to be different. A value of 96 corresponds to 100% font scaling (smaller), 120 corresponds to 125% scaling (medium) and 144 corresponds to 150% scaling (larger). However, users are able to set values other than these standard ones.

    Do be aware that unless your application is declared to be DPI aware, then the values you observe may be subject to DPI virtualization.