2

I want to enable dpi Awareness in our VB.net WinForms Application. So I put the code below into the app.config file. But our project has the checkbox "enable application framework" not checked. Our App starts with a shared sub main and .show(). When the checkbox is not checked I can not enable dpiAwareness! (Since April '19 you can see the dpi mode in the taskmanager) The app.config settings gets ignored?! I dont know.

In Test Projects, there is no problem. There I can check the box and the app.config works or I leave it unchecked and can change the dpi mode at runtime via api call.

</system.diagnostics>
<startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>

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

dpi setting in app.config wont work without "enable application framework" checkbox.

  • 1
    Haven't you answered your own question here: "dpi setting in app.config wont work without "enable application framework" checkbox"? – WSC Oct 10 '19 at 08:17
  • no, I can't check this in our special app. – Jürgen Scheffler Oct 10 '19 at 08:23
  • Weeee, my collegues agreed now @WSC we drop the shared sub main method and check the checkbox. Some non trivial work to do, but we will succeed ;) – Jürgen Scheffler Oct 10 '19 at 08:56
  • You can set the same configuration using an `app.manifest`. – Jimi Oct 10 '19 at 09:43
  • 1
    You also have some ad-hoc native methods you can call. See the notes [here](https://stackoverflow.com/a/50276714/7444103) – Jimi Oct 10 '19 at 09:54
  • I tried using the native methods, but our structure is so old and bad, that I would have to rewrite the whole App Start routines. (I need a App.Run(form) there.... @Jimi: I tried to only use the manifest 4 that, but it did not work, maybe I test again now, with a newly generated manifest...thx@all – Jürgen Scheffler Oct 10 '19 at 10:55
  • I tried the brand new manifest: Result: it changes from "system" to "unkown". So it does not help. – Jürgen Scheffler Oct 10 '19 at 11:02
  • 1
    You didn't post the code that's failing (when it shouldn't), so nobody can see what you actually wrote in the `app.manifest` file. Note that in the `app.manifest` file, both and entries need to be there and the setting (the litteral value) is not equal to the `app.config` one. – Jimi Oct 10 '19 at 16:56
  • 1
    If you want use the app.config file to declare DPI awareness for .Net 4.7 and above, you also have to modify the app.manifest file (Project Properties->Application->View Window Settings button) and declare the program to Win 10 compatible. See: [Configuring your Windows Forms app for high DPI support](https://learn.microsoft.com/en-us/dotnet/framework/winforms/high-dpi-support-in-windows-forms#configuring-your-windows-forms-app-for-high-dpi-support). If using the app.config method, **do not* set the dpi level in the app.manifest file as that will override the app.config settings. – TnTinMn Oct 11 '19 at 03:53

1 Answers1

1

Enable the Win Version like TnTinMn said:

If you want use the app.config file to declare DPI awareness for .Net 4.7 and above, you also have to modify the app.manifest file (Project Properties->Application->View Window Settings button) and declare the program to be Win 10 compatible. See: Configuring your Windows Forms app for high DPI support. If using the app.config method, do not set the dpi level in the app.manifest file as that will override the app.config settings.

Before we take a newly generated mainfest file and add the settings we need since years. We start the app as "application framework enable" in the Project Settings. Then we have to move the shared main code to the main form. I think this should do the job. thx at all.

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
  • Now I open another Dialog Form from th app and I get: System.Collections.Generic.KeyNotFoundException HResult=0x80131577 Nachricht = Der angegebene Schlüssel war nicht im Wörterbuch angegeben. Quelle = mscorlib Stapelüberwachung: at System.ThrowHelper.ThrowKeyNotFoundException() at System.Collections.Generic.Dictionary`2.get_Item(TKey key) at System.Windows.SystemResources.GetDpiAwarenessCompatibleNotificationWindow( – Jürgen Scheffler Oct 22 '19 at 11:42