dotnet / winforms

Windows Forms is a .NET UI framework for building Windows desktop applications.
MIT License
4.28k stars 956 forks source link

Form and controls are not scaled well on HDPI primary monitor when setting custom ApplicationDefaultFont #11608

Open Olina-Zhang opened 1 week ago

Olina-Zhang commented 1 week ago

.NET version

9.0.100-preview.7.24323.5

Did it work in .NET Framework?

Not tested/verified

Did it work in any of the earlier releases of .NET Core or .NET 5+?

Yes, it cannot repro in .NET 8.0

Issue description

When setting custom ApplicationDefaultFont for Winforms .NET 9.0 application, added controls and form are not scaled well on HDPI primary monitor, especially the larger the DPI value, the more pronounced the results look

150%DPI with .NET 9.0: image 225%DPI with .NET 9.0: image 225%DPI with .NET 8.0: image

Steps to reproduce

  1. Create a Winforms .NET 9.0 app
  2. In .csproj file, add following ApplicationDefaultFont content: <ApplicationDefaultFont>Calibri,13pt,style=regular</ApplicationDefaultFont>
  3. Open form designer, add some controls
  4. Build and run app on HDPI primary monitor
kirsan31 commented 1 week ago

I want to add some more details:

  1. The bug exist only with csproj + ApplicationConfiguration.Initialize();. If instead we set font in Program.cs like this: Application.SetDefaultFont(new System.Drawing.Font("Calibri", 13)); - all work fine.
  2. The bug exist only when you start app in high dpi. When start with 100% and then increase - all work fine.
merriemcgaw commented 6 days ago

@kirsan31 - thank you for the details!

elachlan commented 5 days ago

Issue was found when testing PR #11206

Epica3055 commented 1 day ago

Looks like this issue is caused by PR 10525