简体   繁体   中英

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. 在窗口内更改高 dpi

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM