Search code examples
c#.netwinformsscalingdpi

Windows High DPI Scaling for WinForm


This is something I had a lot of trouble with. After days of experimenting, I finally figured out how to properly scale WinForms. This might help some other folks too.

There are a lot of recommendations of modefying the app.manifest or app.config files. The solution might have worked with earlier versions of Windows, but none worked for me. After installing my application, pictures and controls got messed up (in Visual Studio debugging it all worked). After some testing, I had seen that changing the "overwrite high dpi scaling" option setting to "application" worked for me. But I wanted to support this right within the app and not modifying some Windows settings. Changing high dpi inside windows

I stumbled across a Windows support document explaining, that they have changed some DPI scaling with the latest release of Windows and old methods might not work.


Solution

  • All you actually have to do is following these steps:

    1. Locate your app.config
    2. Between </startup> and <userSettings>, insert the following snippet
    <System.Windows.Forms.ApplicationConfigurationSection>
      <add key="DpiAwareness" value="PerMonitorV2" />
    </System.Windows.Forms.ApplicationConfigurationSection>
    
    1. Save the file and reload your project
    2. Make sure, that you have removed any other adjustments from your manifest
    3. Set this in your main method or entry point

    Application.EnableVisualStyles()

    That's it! Your app should be looking great in 4K environment after installing on a machine. For further reference, please see this article from Microsoft.