Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change "Override high DPI scaling behavior" in c#

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?

enter image description here

edit: This is not a duplicate. As making an app DPI aware is not the same as DPI scaling heavior

like image 670
Mike_G Avatar asked Aug 18 '17 15:08

Mike_G


People also ask

How do you override high DPI scaling behavior?

Right-click the application, select Properties, select the Compatibility tab, and then select the Disable display scaling on high DPI settings check box.

What does override high DPI scaling behavior mean?

DPI-scaling overrides This forces the process to run in per-monitor DPI awareness mode. This setting was previously referred to as “Disable display scaling on high-DPI settings.” This setting effectively tells Windows not to bitmap stretch UI from the exe in question when the DPI changes. System.

Should I override high DPI scaling behavior Valorant?

Here, you will have to untick an option which says 'Disability Full-screen optimization' and tick on 'Override High DPI Scaling behavior'. As you select 'Apply', there will be an instant boost in your gaming experience and you get more FPS. Though this might sound like a very basic hack, it does bring a difference.

What happens if I disable Display scaling on high DPI settings?

This option was previously known as “Disable display scaling on high DPI settings”, and it does the same thing. System: Windows will use its normal behavior. Applications that don't respect system DPI settings will be “bitmap stretched” to appear larger so they're more easily readable, but will often appear blurry.


1 Answers

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:

  1. High DPI Support

  2. High DPI Desktop Application Development on Windows (also Application Manifests)

  3. DPI Awareness - Unaware in one Release, System Aware in the Other [duplicate]

  4. Writing High-DPI Aware Windows Apps

  5. Writing DPI-Aware Desktop and Win32 Applications

like image 184
abberdeen Avatar answered Oct 14 '22 18:10

abberdeen