-
Notifications
You must be signed in to change notification settings - Fork 1k
Fix 11214 by removing IsHandleCreated in OnFontChanged #11641
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
base: main
Are you sure you want to change the base?
Fix 11214 by removing IsHandleCreated in OnFontChanged #11641
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #11641 +/- ##
===================================================
+ Coverage 74.51776% 75.06831% +0.55055%
===================================================
Files 3040 3059 +19
Lines 629560 632003 +2443
Branches 46839 46782 -57
===================================================
+ Hits 469134 474434 +5300
+ Misses 157058 154190 -2868
- Partials 3368 3379 +11
Flags with carried forward coverage won't be shown. Click here to find out more. |
I'm not sure that this fix addresses all possible cases. Fundamentally, we are missing information about what font/DPI the controls are scaled for right now. This fix assumes that the application was designed for the DefaultFont and that the current sizes are still set to the "initial" sizes. The former assumption is reasonable, the latter is not necessarily true. Maybe the application had been resized a couple of times and the current sizes are not appropriate for the default font anymore. Previous layout design relied on the AutoScaling ratios to maintain the current state as related to the original designed sizes. We would need to either revive that logic or to implement an extention on it. I suggest we revisit this bug in NET10 |
@LeafShi1 - let's revisit this change in NET10 |
@Tanya-Solyanik According to customer feedback, this fix can solve their problem. I tried to change the font several times, setting three different fonts in Form.cs and Form.Designer.cs, and the scaling results were normal. But there is a question, should we scale the font before the handle is created? |
We don't have this information at the Handle creation time. In some cases the requested size will be already scaled by the user app and in some it would be the default size. We have |
Whether the form/control automatically scales should not be linked to the handle I did the following experiment
So whether the form automatically scales should not be linked to the handle. What do you think? |
I'm concerned about scaling for the DPI. At the runtime, the form should be scaled according to the DPI of the screen it's created on from the DPI it was designed on. I.e. if the design time DPI scaling is 100%, but the runtime DPI scaling is 200%, form size should be doubled. If the Form uses AutoScaleMode.Dpi, then font should be rescaled. However, we don't always know what on what screen the control is displayed and we might have to scale font after handle is created, when we know the current screen DPI. And we don't know if the default font had been scaled. It is more efficient to scale the default font and have it applied to all controls in the application than to scale font on each container control. Jeremy is planning to rework the default font handling. So fix for this issue will depend on the new infrastructure that he will put in. Could you please wait with this this change until that work is done? |
OK, I will wait for the new infrastructure |
Redoing layout is not something we're going to get to for a while. We should look at a targeted fix for .NET 10 here, even if it is behind a compat switch. |
@JeremyKuhne Do you mean add an AppContext switch for it? |
If the change is risky, yes. You're undoing #5557, which is concerning. Presuming doing this would break the other fixes. Whatever we do here it would be good to know how this impacts the bugs fixed by that change. |
b72925c
to
2c26f66
Compare
2c26f66
to
a828b34
Compare
This only undoes the changes to @JeremyKuhne @KlausLoeffelmann No other impacts have been found so far, should we stick with the original fix and add a switch here or revert the original change? |
I have a general problem with the Layout scaling, as a series of "fixes" we did in the past opened up different issues. What I would like to do, is before we address this, come up with a specific HighDPI Layout Test App, which we should use in some exploratory settings, and then go from there, to investigate some status-quo first. The question I have is: @Olina-Zhang: Do you have a test scenario, which would basically run on a physical machine (not a VM) and include the following tests. If not, could you schedule some time, and have someone do the following steps and document the respective results via screenshots?
Now. Next: Close all the running Apps and all Visual Studio Instances. Set the Scaling of the machine back to 100%, but if possible do NOT change the resolution. Restart the machine Start VS 2017 and VS 2022, and open all the Forms in the Designer and make screenshots of the Form. IMPORTANT: Do NOT change the Form or its content, also do not resize the Forms. Just open them and make the Screenshots. You can collapse tool Windows of VS which might be in the way, to get a better view of the Form. Now, run all the Apps again, and make individual screenshots and one screenshot showing all of them. Provide all the Screenshots as the test results. @merriemcgaw, @Olina-Zhang, @LeafShi1 FYI. |
Fixes #11214, #12851
Root Cause
PerformAutoScale
is not executed, because when the Form object is created, its handle is not created immediately, and we have added a check in our code that the handle must be created before scaling.Proposed changes
-Add a check on the default font setting in the OnFontChanged function of ContainerControls.cs to ensure that PerformAutoScale is executed smoothly
Customer Impact
Risk
Screenshots
Before
When I adjust the font for the entire application, the controls on the form don't scale appropriately

After
The controls on the form can be scaled appropriately after adjust the font for the entire application

Test methodology
Test environment(s)
Microsoft Reviewers: Open in CodeFlow