[英]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.