方法一:使用注册表覆盖高DPI缩放(勾选复选框)
启动注册表编辑器并导航到此键:
HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers
现在添加一个字符串值(REG_SZ),其名称为应用程序可执行文件的完整路径,其值为HIGHDPIAWARE。
代码示例:
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");
阅读更多:Windows高DPI设置
方式2. 如何在程序集清单中改变DPI感知?
DPI感知应用不受操作系统影响。这类应用会根据屏幕的实际DPI进行渲染,提供更好的视觉体验。
将<dpiAware>
元素添加到清单代码中,并将其值设置为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>
额外资源:
settings.CefCommandLineArgs.Add("force-device-scale-factor", "1");
- TEK