I'm trying to test the possible options for improving the display rendering of my Forms application (before, I was using an application settings boolean to invoke (or not) SetProcessDPIAware() when starting the application. The only way I found to change the rendering is by adding <ApplicationHighDpiMode>xxxx</ApplicationHighDpiMode> in <PropertyGroup> of the csproj file (xxxx stands for one of the following: DpiUnaware, SystemAware, PerMonitor, PerMonitorV2, DpiUnawareGdiScaled).
I would like to be able to change the DPI handling programmatically, so I have added the code to do it into Program.cs:
public static string DpiVal = "";
ApplicationConfiguration.Initialize();
<ApplicationHighDpiMode>DpiUnawareGdiScaled</ApplicationHighDpiMode>
HighDpiMode dpi = (HighDpiMode)Properties.Settings.Default.DpiMode;
Application.EnableVisualStyles();
bool status = Application.SetHighDpiMode(dpi);
DpiVal = string.Format("SetHighDpiMode({0}) returned {1}. Current HighDpiMode: {2}.", dpi, status, Application.HighDpiMode.ToString());
Application.Run(new Form1());
The contents of the string variable DpiVal is printed in the main form (I playing with a small test program) and I can see that SetHighDpiMode ALWAYS returns false and that the property HighDpiMode never changes.
SetHighDpiMode(PerMonitorV2) returned false. Current HighDpiMode: SystemAware.
According to the documentation, false will be returned only if HighDpiMode is already specified in the manifest (explicitly or via csproj file, I presume). Yet, even if I have a default manifest file or no manifest file at all (and, of course, no ApplicationHighDpiMode in my csproj file) SetHighDpiMode() still returns false.
Am I doing something wrong?
Additional question: how exactly to specify ApplicationHighDpiMode in the manifest file? Is there some special group, like <PropertyGroup> in csproj file?