使 vb.net 应用程序 DPI 感知
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23101791/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Make vb.net application DPI aware
提问by user2452250
I need to make my vb.net app scale up properly on any DPI setting. Currently it gets messed up if the setting is anything other than standard.
我需要让我的 vb.net 应用程序在任何 DPI 设置上正确扩展。目前,如果设置不是标准设置,它会变得一团糟。
Everything i found refers either to c# or to older versions of VB or to Visual Studio Pro and are not compatible to the version I am using.
我发现的所有内容都涉及 c# 或旧版本的 VB 或 Visual Studio Pro,并且与我使用的版本不兼容。
I am on Visual studio express 2013.
我在 Visual Studio Express 2013 上。
Thanks
谢谢
回答by Matt Wilko
Taken from the article WinForms scaling at large DPI settings – is it even possible?on the Telerik web page
取自文章WinForms 在大 DPI 设置下缩放 – 甚至可能吗?在 Telerik 网页上
Declaring the DPI awareness is done in a manifest file.
You can use the following markup to set the dpiAware flag. Possible values are True for DPI-aware app, False for non-DPI-aware app and True/PM for per-monitor-DPI-aware app.
声明 DPI 感知是在清单文件中完成的。
您可以使用以下标记来设置 dpiAware 标志。对于 DPI 感知应用程序,可能的值为 True,对于非 DPI 感知应用程序为 False,对于每显示器 DPI 感知应用程序,可能的值为 True/PM。
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" >
<asmv3:application>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true</dpiAware>
</asmv3:windowsSettings>
</asmv3:application>
</assembly>
The WinForms platform has its own scaling mechanism which calculates the scaling difference between the system that the form has been designed on and the system it is running on. Then it modifies the size and the location of all controls according to the calculated factor. Note that this scaling will only trigger if your application declares to be DPI-aware, otherwise it will be rendered in the 96 DPI sandbox and the bitmap scaling of the OS will be used.
WinForms 平台有自己的缩放机制,可以计算设计表单的系统和运行它的系统之间的缩放差异。然后它根据计算的因子修改所有控件的大小和位置。请注意,此缩放仅在您的应用程序声明为 DPI 感知时才会触发,否则它将在 96 DPI 沙箱中呈现并使用操作系统的位图缩放。

