由于如今高分屏愈来愈多,不少windows设备必须设置高DPI,这样很容易致使WINFORM总体错位,所以咱们须要本身适配。禁止缩放windows
在程序配置清单 mainfest中添加以下。app
<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>
其中dpiAware节点参数MSDN解释以下,各取所需吧。函数
False -- Sets the application to not DPI-aware. True -- Sets the application to system DPI–aware. Per-monitor -- On Windows 8.1, sets the application to per monitor-DPI aware. On Windows Vista through Windows 8, sets the application to not DPI–aware. True/PM -- On Windows 8.1, sets the application to per monitor-DPI aware. On Windows Vista through Windows 8, sets the application to system-DPI aware.
注意这个红字部分,有的人自动生成mainfest以后不会添加这个节点,其实只要在第一行添加这个红字部分就好了spa
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" >
第一行改为这样就好了code
<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" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
其次上面只是设置了感知,你要具体去改,在构造函数中,组建生成以前 添加如文字感知:xml
Font = new Font(Font.Name, 8.25f * 96f / CreateGraphics().DpiX, Font.Style, Font.Unit, Font.GdiCharSet, Font.GdiVerticalFont); InitializeComponent();
这样基本上你的窗体就不会被缩放了。blog