简体   繁体   English

Winforms应用程序在绘制图表时更改高dpi监视器上的缩放比例

[英]Winforms application changes scaling on high dpi monitor when drawing a chart

I have a Winforms Application (C#, .NET 4.7) that has no problems on my system with a 1920x1080 monitor. 我有一个Winforms应用程序(C#、. NET 4.7),在使用1920x1080显示器的系统上没有问题。 I have set the AutoScaleMode to Font for my main window, and added the true to my manifest. 我在主窗口中将AutoScaleMode设置为Font,并将true添加到清单中。 Running the program on a computer with a High resolution (3840x2160) screen seems to work fine as well. 在具有高分辨率(3840x2160)屏幕的计算机上运行该程序似乎也可以正常工作。 All is scaled correct and everything is readable. 一切都正确缩放,并且一切都可读。 Until I open a datafile and display the results on the Map or Chart control. 直到我打开数据文件并在“地图”或“图表”控件上显示结果。 Then the whole program suddenly rescales to about 50% of it's original size and all fonts become unreadable small. 然后整个程序突然重新缩放到其原始大小的大约50%,并且所有字体变小了。 Changing the font size or resolution using the Windows display settings has no effect. 使用Windows显示设置更改字体大小或分辨率无效。 What could cause this runtime scaling, and how can I work around this ? 是什么原因导致运行时缩放,我该如何解决?

After following all best practices as described in this post: it still does not work. 遵循本文所述的所有最佳做法后:它仍然不起作用。 Another comprehensive explanation on the Telerik website however put me on the right track. 但是,Telerik网站上的另一个综合说明使我走上了正确的道路。 The problem was caused by the GMap control, but could be caused by any third party control that was designed on a different system. 该问题是由GMap控件引起的,但可能是由在不同系统上设计的任何第三方控件引起的。 The control contained a scaling setting in the Designer.cs file: 该控件在Designer.cs文件中包含一个缩放设置:

this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);

This setting is added automatically by the IDE when you create a new control and is based on the DPI settings of system it is created on. 当您创建新控件时,此设置由IDE自动添加,并且基于创建该控件的系统的DPI设置。 On a 96 DPI system this is always 在96 DPI系统上,这始终是

this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

So all the forms I had created for my app had this 96DPI based setting, but the GMap control had a different setting. 因此,我为我的应用创建的所有表单都具有基于96DPI的设置,但是GMap控件具有不同的设置。 And when the GMap control was redrawn it caused the whole application to scale using the incorrect AutoScaleDimensions. 重新绘制GMap控件时,它导致整个应用程序使用错误的AutoScaleDimensions进行缩放。 The solution is simply to search for all occurrences of AutoScaleDimensions and set them all to (6F,13F). 解决方案只是搜索所有出现的AutoScaleDimensions,并将它们全部设置为(6F,13F)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WinForms:如何修复 Forms 在具有不同分辨率/缩放的高 DPI、多监视器环境 (PerMonitorV2) 中的不正确缩放 - WinForms: How to fix incorrect scaling of Forms in high-DPI, multi-monitor environments (PerMonitorV2) with different resolution/scaling 禁用高 DPI 缩放 - Disable high DPI scaling 如何通过代码以编程方式将“覆盖高 DPI 缩放”设置为“应用程序” - How to set “Override high DPI scaling” to “Application” programmatically through code WinForm 的 Windows 高 DPI 缩放 - Windows High DPI Scaling for WinForm .NET WinForms 高 DPI 缩放 - 如何在显示设置更改后强制 forms 正确显示? - .NET WinForms high DPI Scaling - how to force forms to display correctly after display settings change? 用于绘图应用程序的RenderTargetBitmap DPI - RenderTargetBitmap DPI for drawing application C# WinForms 禁用 DPI 缩放 - C# WinForms disable DPI scaling 如何创建与Windows 7向后兼容的缩放和大小更改Per-Monitor DPI感知应用程序? - How to create a scaling and size-changing Per-Monitor DPI-aware application that is backwards compatible with Windows 7? WinForm在运行时改变大小...高DPI相关? - WinForm changes size at runtime… high DPI related? 在具有不同分辨率/缩放比例的显示器之间拖动表单时,ContextMenuStrip 不会进行 DPI 缩放(WinForms、.NET 6.0、PerMonitorV2) - ContextMenuStrip doesn't DPI scale when Form is dragged between monitors with different resolution/scaling (WinForms, .NET 6.0, PerMonitorV2)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM