-
Notifications
You must be signed in to change notification settings - Fork 998
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Font autoscaling doesn't function in .NET Core as it does in .NET Framework 4.8. #11214
Comments
This issue should probably be moved to dotnet/winforms. |
@swapso I believe what you're seeing is expected and by design due to the change in the default font (documented here). To ease the pain of the migration in .NET 6 we introduced Application.SetDefaultFont API and the application bootstrap (documented here, blogged here). I would also recommend reviewing the list of the breaking changes Windows Forms SDK accepted moving from .NET Framework to .NET. |
@RussKie, you're spot on. It only functions correctly when the forms are already open, as |
Difference between NET 4.8 & NET Core font scaling.pdf Hi @RussKie @Suchiman Please go through it once. |
Thank you @swapso, that's for @dotnet/dotnet-winforms team to investigate. |
This problem can be reproduced by setting a larger font size for the form and making the control layout in the Form more compact. |
@merriemcgaw @LeafShi1 @ricardobossan |
@merriemcgaw @ricardobossan @Tanya-Solyanik So the way to fix this problem
|
@merriemcgaw I will test the changes and let you know soon |
Hi @merriemcgaw , @LeafShi1 @Tanya-Solyanik Document: https://github.com/dotnet/winforms/blob/main/docs/debugging.md am I missing something? |
Is there any error? You can try to upgrade the .net SDK to latest version. |
@LeafShi1
|
@swapso You may have misunderstood the workaround I provided. You don't need to change the Winform code. You only need to add CreateHandle(); in your Application. |
@LeafShi1 oh thanks. I already tried & tested adding CreateHandle(); in my application and it works. But to close this issue, I guess I need to change in Winform code and then submit a PR for this issue. Isn't it? Or you guys will do it? |
@LeafShi1 Sorry for the confusion what I write in earlier comment. The CreateHandle(); worked in my sample application for single form only. When I tried to put it in base form, it just don't work. |
I see. Font settings may be more complicated in real applications. CreateHandle(); can only solve the problem of setting the default font when the Form is initially sized. We will revisit this issue. |
There's also an issue with a specific nesting of controls that won't allow auto-scaling for some controls. When a control is placed in a SplitContainer inside a TabControl on its second page, this control isn't included in the auto-scaling until after the second page has been created (selected). |
Hi @LeafShi1 I made the changes you provided in winform code. Built and exported DLL and tested it with my application. it works. Every contols are properly scaled according to font size. Steps I took:
@Camel-RD even tested your application 'TestAutoScaleOnFontChange.zip' , it also work with that. code changes in winform screenshot attached below. (updated if condition) @LeafShi1 Let me know so we can close this issue. |
Thanks for your feedback, we need to discuss the feasibility of this fix and whether it can solve all possible situations. |
@LeafShi1 if we can move faster, we want these small changes to go live in the next .NET preview version Or get added in the previous version .NET Let me know how can I help to do it faster. |
For issue tracking, please see the comment below PR #11641 |
@LeafShi1 why PR#11641 is closed? What happened to new infrastructure that Jeremy was planning to rework. |
I can't give a specific time for the new infrastructure, closing this PR is to avoid outdated code, which will increase merge conflicts and make review difficult. When the new infrastructure is completed, I will submit a new PR |
@LeafShi1 any update? |
Sorry for the late reply! I cannot provide a detailed infomation to you. @JeremyKuhne is working on creating new infrastructure, I will update you if there are any updates. |
@swapso redoing layout is a very large feature which has no specific delivery date yet. We'll try to do a targeted fix for this in .NET 10. |
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
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
The text was updated successfully, but these errors were encountered: