越来越多的用户使用高分屏作为客户端显示器,通常会将屏幕缩放比例设置为大于100%,此时winforms应用如果没有配置对高dpi的支持,可能出现显示大小不符预期,显示模糊,错位等问题
要给Spread控件添加对高DPI的支持,首先也需要先给所在的winform应用本身设置高分支持
以.NET Framework 4.7 以上的应用为例,设置步骤如下
1.将包含以下信息的 App.config 添加到表单的根目录(与 Program.cs 相同的目录)。
- <?xml version="1.0" encoding="utf-8"?>
- <configuration>
- <startup>
- <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7"/>
- </startup>
- <System.Windows.Forms.ApplicationConfigurationSection>
- <add key="DpiAwareness" value="PerMonitorV2"/>
- <!-- Uncomment each value to disable the fixes one by one. -->
- <!--
- <add key="Form.DisableSinglePassScalingOfDpiForms" value="true"/>
- <add key="ToolStrip.DisableHighDpiImprovements" value="true"/>
- <add key="CheckedListBox.DisableHighDpiImprovements" value="true"/>
- <add key="MonthCalendar.DisableHighDpiImprovements" value="true"/>
- <add key="AnchorLayout.DisableHighDpiImprovements" value="true"/>
- <add key="DataGridView.DisableHighDpiImprovements" value="true"/>
- -->
- </System.Windows.Forms.ApplicationConfigurationSection>
- </configuration>
-
复制代码 2.将包含以下信息的 App.manifest 添加到表单的根目录(与 Program.cs 目录相同)。
- <?xml version="1.0" encoding="utf-8"?>
- <assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
- <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 element will disable file and registry virtualization.
- Remove this element if your application requires this virtualization for backwards
- compatibility.
- -->
- <requestedExecutionLevel level="asInvoker" uiAccess="false" />
- </requestedPrivileges>
- </security>
- </trustInfo>
- <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
- <application>
- <!-- A list of the Windows versions that this application has been tested on and is
- is designed to work with. Uncomment the appropriate elements and Windows will
- automatically selected the most compatible environment. -->
-
- <!-- Windows 10 -->
- <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
- </application>
- </compatibility>
- <!--<application xmlns="urn:schemas-microsoft-com:asm.v3">
- <windowsSettings>
- <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
- </windowsSettings>
- </application>-->
-
- </assembly>
-
复制代码 3.验证 Program.cs 是否具有以下设置。
- static class Program
- {
- /// <summary>
- /// The main entry point for the application.
- /// </summary>
- [STAThread]
- static void Main()
- {
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
- Application.Run(new Form1());
- }
- }
-
复制代码 4.在 Form1.designer.cs 中添加以下对Form和Spread的设置
- this.fpSpread1.SpreadScaleMode = FarPoint.Win.Spread.ScaleMode.ZoomDpiSupport;
- this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
-
复制代码
|
|