今天下午讲的一节Webcast中重点介绍了High DPI,关于这个内容由于虚机中不支持DPI Aware的原因,没有做成Demo,现在给大家一个教程,希望对大家在的程序支持Windows 7系统有所帮助:
1. 创建一个托管应用程序(VB.NET或C#皆可,我这里用C#做一个例子):
2. 右击选择项目并添加一个app.manifest文件:
3. 使用下面的代码覆盖该文件:
<?
xml version="1.0" encoding="utf-8"
?>
< asmv1:assembly manifestVersion ="1.0" xmlns ="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1 ="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2 ="urn:schemas-microsoft-com:asm.v2" xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance%22>
<assemblyIdentity version=" 1.0.0.0" name ="MyApplication.app" />
< asmv3:application xmlns:asmv3 ="urn:schemas-microsoft-com:asm.v3" >
< asmv3:windowsSettings xmlns ="http://schemas.microsoft.com/SMI/2005/WindowsSettings%22>
<dpiAware>true</dpiAware>
</asmv3:windowsSettings>
</asmv3:application>
<trustInfo xmlns=" urn:schemas-microsoft-com:asm.v2" >
< security >
< requestedPrivileges xmlns ="urn:schemas-microsoft-com:asm.v3" >
<!-- UAC Manifest Options
If you want to change the Windows User Account Control level replace the
requestedExecutionLevel node with one of the following.
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
If you want to utilize File and Registry Virtualization for backward
compatibility then delete the requestedExecutionLevel node.
-->
< requestedExecutionLevel level ="asInvoker" uiAccess ="false" />
</ requestedPrivileges >
</ security >
</ trustInfo >
</ asmv1:assembly >
< asmv1:assembly manifestVersion ="1.0" xmlns ="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1 ="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2 ="urn:schemas-microsoft-com:asm.v2" xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance%22>
<assemblyIdentity version=" 1.0.0.0" name ="MyApplication.app" />
< asmv3:application xmlns:asmv3 ="urn:schemas-microsoft-com:asm.v3" >
< asmv3:windowsSettings xmlns ="http://schemas.microsoft.com/SMI/2005/WindowsSettings%22>
<dpiAware>true</dpiAware>
</asmv3:windowsSettings>
</asmv3:application>
<trustInfo xmlns=" urn:schemas-microsoft-com:asm.v2" >
< security >
< requestedPrivileges xmlns ="urn:schemas-microsoft-com:asm.v3" >
<!-- UAC Manifest Options
If you want to change the Windows User Account Control level replace the
requestedExecutionLevel node with one of the following.
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
If you want to utilize File and Registry Virtualization for backward
compatibility then delete the requestedExecutionLevel node.
-->
< requestedExecutionLevel level ="asInvoker" uiAccess ="false" />
</ requestedPrivileges >
</ security >
</ trustInfo >
</ asmv1:assembly >
4. 在Form1窗体上添加一些ToolBox的按钮:
5. 再创建一个项目:
6. 不要添加Manifest,直接在Form1上添加几个Toolbox的按钮:
7. 将解决方案编译好:
8. 在桌面属性选择Display:
9. 选择DPI为150%:
10. 登出系统再登录就可以应用该设置:
11. 打开刚才编译好的两个应用程序就可以看到不同了:
两个程序哪个是DPI Aware的呢,大家可以猜猜,好,本文就到此,感谢!