情况如下:我有一个表单frmCompanyMasterEdit,它继承frmBaseEdit,继承frmBase,继承System.Windows.Forms.Form。这些都是WinForms。
因此,我正在尝试获得frmCompanyMasterEdit (一种允许用户编辑有关公司的详细信息的表单;实际上所有的表单,但这只是一个例子)是4K兼容的,这就是为什么我在继承链上所有提到的表单(frmBase、frmBaseEdit、frmCompanyMaster)中将属性从Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font更改为Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi的原因。
问题是,当我在一个4k (3840x2160)的显示器上看到它的200%时,它太大了。表单之前做得很好,但我所做的只是改变了这个属性,当我现在把它们拉上来时,它使我的表单变得很大。我不知道为什么。我正在使用VB.NET,VisualStudio2017运行Windows 10,我们没有资源来升级到WPF。
frmBase.designer.vb - Me.AutoScaleDimensions = New System.Drawing.SizeF(192.0!, 192.0!)
下面的app.manifest文件
<?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">
<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">
<!-- 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" />
Specifying requestedExecutionLevel node will disable file and registry virtualization.
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>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- A list of all Windows versions that this application is designed to work with.
Windows will automatically select the most compatible environment.-->
<!-- If your application is designed to work with Windows Vista, uncomment the following supportedOS node-->
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"></supportedOS>-->
<!-- If your application is designed to work with Windows 7, uncomment the following supportedOS node-->
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>-->
<!-- If your application is designed to work with Windows 8, uncomment the following supportedOS node-->
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"></supportedOS>-->
<!-- If your application is designed to work with Windows 8.1, uncomment the following supportedOS node-->
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>-->
</application>
</compatibility>
<!-- Add in each application's manifest to make application DPI aware-->
<asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<asmv3:windowsSettings
xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>True</dpiAware>
</asmv3:windowsSettings>
</asmv3:application>
<!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
<!-- <dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>-->
</asmv1:assembly>标题编辑:对不起,不是"4K兼容“,因为他们在技术上兼容4k,我的意思是看起来很好/锐利在4K。
发布于 2018-02-21 17:58:57
我建议将表单缩放到不同的DPI,以避免设计人员设置的默认设置。
在设计器中,将AutoScaleMode设置为继承,而不是默认的字体。然后向表单的代码中添加一个默认构造函数(Public Sub New()),并在那里定义自动缩放信息。
Public Sub New()
InitializeComponent()
Me.AutoScaleDimensions = New System.Drawing.SizeF(96.0!, 96.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi
End SubAutoScaleDimensions属性设置为96 DPI以前是显示设备(屏幕)的基本DPI。
通过在构造函数中声明这些属性,而不是在designer生成的InitializeComponent`方法中声明这些属性,您确实会丢失此特定表单的designer视图中的缩放;缩放将在运行时应用。从它继承的任何窗体都将在设计器中应用缩放显示,并且应该显示与运行时相同的大小。
接下来,清单(添加一个app.manifest)应用程序声明它是新闻部感知的。新闻部有各种提高认识的办法,但最基本的办法是:
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
</windowsSettings>
</application>奇怪的是,我照你说的做了(用AutoScaleDimensions),现在这个表单不是“大”的,但是它有点小,标签和文本框是紧密相连的。
基于当前设计环境中的VS覆盖因素所造成的破坏后,修复这一问题是一场反复尝试的游戏。如果窗体看起来很小,请尝试使用不同的基比例因子。由于(96.0!, 96.0!)太小,下一个合理的尝试将是(120.0!, 120.0!);也就是说,表单最初是以125% (96 * 1.25 = 120)的缩放因子设计的。
最后,确保表单在所有显示分辨率/DPI配置中看起来都是正确的。您可能需要为某些配置实现特定的缩放机制。
https://stackoverflow.com/questions/48893579
复制相似问题