2

I have a WinForm application and I am migrating it from .net-framework to .net-core. In .Net Frameworks, I use the app.config file to enable DpiAwareness. At the same time I set EnableWindowsFormsHighDpiAutoResizing to false so I can handle the resizing myself.

 <System.Windows.Forms.ApplicationConfigurationSection>
    <add key="DpiAwareness" value="PerMonitorV2" />
    <add key="EnableWindowsFormsHighDpiAutoResizing" value="false" />
  </System.Windows.Forms.ApplicationConfigurationSection>

In .Net Core, the app.config doesn't seems make any difference anymore. I can use Application.SetHighDpiMode to enable Dpi mode, but I cannot find a way to update EnableWindowsFormsHighDpiAutoResizing.

I have tried manually make a myapp.exe.config file and using runtime.config.json, no luck. How to update EnableWindowsFormsHighDpiAutoResizing in .Net Core?

Zj Wine
  • 125
  • 12
  • [HighDpiMode API Extension](https://github.com/dotnet/winforms/pull/396) --> [Merge pull request #396 from dotnet/dev/klloeffe/HighDpiMode](https://github.com/dotnet/winforms/commit/4608b70a8534b8168c718431b316ba7a6cecfa16) (`public static bool SetHighDpiMode(HighDpiMode highDpiMode) { ... }` --> [Application.SetHighDpiMode(HighDpiMode)](https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.application.sethighdpimode?view=netcore-3.1&viewFallbackFrom=netframework-4.8). Some related notes on the methods used [here](https://stackoverflow.com/a/50276714/7444103) – Jimi Sep 18 '20 at 23:36
  • You are probably aware of the state and support of WinForms under .Net Core 3.1, at this time. – Jimi Sep 18 '20 at 23:37
  • thanks @Jimi, my question was downvoted so I just updated it to be more clear. Both SetHighDpiMode and app.manifest work for me to enable dpi awareness, but neither way can disable EnableWindowsFormsHighDpiAutoResizing. What's the state and support of WinForms in .Net Core? I just know there are some breaking changes https://learn.microsoft.com/en-us/dotnet/core/compatibility/winforms – Zj Wine Sep 18 '20 at 23:52
  • Have you checked what is the configuration file in .Net Core? + .Net 5 is in RC1, maybe you can wait for it? – Jimi Sep 19 '20 at 00:13
  • .net core has runtime.json file where I can set some configurations, but didn't work for me. There is also configuration builder that can read appsettings.json, but that seems like just for loading settings instead of configuring dpi behavior. – Zj Wine Sep 19 '20 at 00:34
  • Have you added the app.manifest to the project? What's available and can work is there. You can always handle the Dpi Change events that are raised at Form level to handle custom resizing. That setting also corrects some Dpi scaling issues with older Win32 Controls. – Jimi Sep 19 '20 at 02:47
  • Yes I have tried app.manifest, but EnableWindowsFormsHighDpiAutoResizing was not an option there. We am currently handling dpi scaling ourselves, therefore I am hoping to set EnableWindowsFormsHighDpiAutoResizing to false. – Zj Wine Sep 21 '20 at 21:11

0 Answers0