简体   繁体   中英

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. I have set the AutoScaleMode to Font for my main window, and added the true to my manifest. Running the program on a computer with a High resolution (3840x2160) screen seems to work fine as well. 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. Changing the font size or resolution using the Windows display settings has no effect. 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. The problem was caused by the GMap control, but could be caused by any third party control that was designed on a different system. The control contained a scaling setting in the Designer.cs file:

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. On a 96 DPI system this is always

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. And when the GMap control was redrawn it caused the whole application to scale using the incorrect AutoScaleDimensions. The solution is simply to search for all occurrences of AutoScaleDimensions and set them all to (6F,13F).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM