Font autoscaling doesn't function in .NET Core as it does in .NET Framework 4.8. #11214
Description
Description
I've just migrated a Winform project from .NET Framework 4.8 to .NET Core 9, following the porting instructions provided in the Windows documentation. However, I've encountered an issue with font autoscaling. When I adjust the font for the entire application, the controls on the form don't scale appropriately.
Reproduction Steps
- Create small Multi-windows winform application (an app which can open multiple forms in the same app) based on .NET Framework 4.8 having a single form with basic ui control like labels, buttons, textboxes.
- Create a form of changing font of entire application in the application.
- Port above .NET 4.8 project to using .NET core with latest version (Also, keep copy of .Net 4.8 version)
- Run both project, open a form, observe controls properties before and after changing font size.
- For reference, .NET 4.8 uses default 'Microsoft san serif' with 8.25 Small font size and .Net core uses 'Segoe UI' with 9 small font size.
Expected behavior
In a NET Core project, after changing the font, the properties of the controls like SizeX, SizeY, LocationX, and LocationY should be set to the same values as in the NET 4.8 project during events like onLoad, onShown, and FontChanged.
I have attached my application expected screenshot.
Actual behavior
In a NET Core project these properties are not getting set correctly, which ultimately causing winform UI to set weirdly.
I have attached my application actual screenshot.
Regression?
No response
Known Workarounds
Above is NET 4.8 code from System.Windows.Forms->Systems->Windows->Forms->Layout->Containers->ContainerControls.cs
and below is the same code from NET Core
Look at difference, because of base.IsHandleCreated NET Core doesn't allow to take effect of FontChanged.
if we remove that base.IsHandleCreated
from code and test the application it works fine.
Configuration
.NET version- 4.8 and .NET Core
Windows 10
x64 Architecture
Other information
No response