14

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

abberdeen
  • 323
  • 7
  • 32
Mike_G
  • 16,237
  • 14
  • 70
  • 101
  • 1
    @hans-passant This is not a duplicate. As making an app DPI aware is not the same as DPI scaling heavior – Mike_G Aug 18 '17 at 16:04
  • Are you looking to force device scale factor? The following setting to prevent the browser from scaling when using a higher DPI `settings.CefCommandLineArgs.Add("force-device-scale-factor", "1");` – TEK Aug 18 '17 at 21:16
  • @TEK Thanks for the suggestion, but the issue still persist. – Mike_G Aug 22 '17 at 14:51
  • @Mike_G Did you find a solution? I'm having the exact same problem. – Juan Feb 21 '18 at 03:54
  • @Juan No, unfortunately we just started building our controls in xaml – Mike_G Feb 21 '18 at 13:10
  • Original dup link for programmers that look for the correct solution: https://stackoverflow.com/a/13228495/17034 – Hans Passant Jul 19 '18 at 20:55

1 Answers1

8

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

abberdeen
  • 323
  • 7
  • 32
  • It did not work. The 'Override high DPI scaling behavior' checkbox is still not checked. – nikotromus Jul 19 '18 at 21:00
  • asmv3 is prefix of target namespace . – abberdeen Jul 19 '18 at 21:02
  • 'Override high DPI scaling behavior' checkbox will not be checked. But effect is same to checked – abberdeen Jul 19 '18 at 21:03
  • But this check box is exactly what I am trying to accomplish. – nikotromus Jul 19 '18 at 21:04
  • I dont know, it should fix your problem without checking. If it fixes there is no need for checking checkbox, I think. Also for correct testing you need unckeck that checkbox – abberdeen Jul 19 '18 at 21:07
  • Ok. I will try to test it and let you know what happens. Thank you so much! – nikotromus Jul 19 '18 at 21:18
  • Read https://github.com/cefsharp/CefSharp/wiki/General-Usage#high-dpi-displayssupport – amaitland Jul 19 '18 at 22:15
  • @Los Pollos Hermanos - FYI great name by the way. The change in the manifest file did not have the same effect as checking the box and then selecting 'system' in the drop down. It didn't work. – nikotromus Jul 20 '18 at 12:36
  • After that box for 'Override High DPI' is checked, the drop down list is available to change. When I check the 'Override High DPI' box, and then select 'system' instead of 'application', I get the desired results. I'm trying to figure out how to change that setting in the manifest file now. – nikotromus Jul 20 '18 at 13:51
  • 2
    It works!!! Here is the alteration I made to give the desired effect for my situation: true/system Thank you SOO much!!! I'll award the bounty in three more hours when the system will allow me to. – nikotromus Jul 20 '18 at 14:38