Reputation: 16512
We have a control inside a WinForm (CefSharp control) that suffers from graphical artifacts when a users screen is set to 125% on windows. Its not just the control, stand alone Chrome does it to an extent. The only way we have been able to fix the artifacts is by changing the exe setting pictured below. Is there a way to change it in code?
edit: This is not a duplicate. As making an app DPI aware is not the same as DPI scaling heavior
Upvotes: 14
Views: 6318
Reputation: 346
Way 1. How Override high DPI scaling (check checkbox) with registry
Start up Registry Editor and navigate to this key:
HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers
Now add a string value (REG_SZ) whose name is the full path to the application executable and whose value is HIGHDPIAWARE
Code example:
string appPath = string.Format(@"{0}\{1}.exe", My.Application.Info.DirectoryPath, My.Application.Info.AssemblyName);
My.Computer.Registry.SetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers", appPath, "HIGHDPIAWARE");
Read more: High DPI Settings in Windows
Way 2. How to change DPI-aware in assembly manifest?
DPI-aware applications are not affected by the OS. Such applications render themselves to fit the actual DPI of a screen and provide a much better visual experience.
Add the <dpiAware>
element to the manifest code and set its value to true
.
<?xml version="1.0" encoding="utf-8"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" >
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
<asmv3:application>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true</dpiAware>
</asmv3:windowsSettings>
</asmv3:application>
</assembly>
Additional resources:
High DPI Desktop Application Development on Windows (also Application Manifests)
DPI Awareness - Unaware in one Release, System Aware in the Other [duplicate]
Upvotes: 8