Skip to content

Fix UpDown control layout when changing and resetting fonts - #15374

Merged
LeafShi1 merged 2 commits into
mainfrom
Fix_15331_Size_and_Location_of_UpDownControl_restore
Nov 11, 2026
Merged

LeafShi1 merged 2 commits into
mainfrom
Fix_15331_Size_and_Location_of_UpDownControl_restore

Conversation

@LeafShi1

@LeafShi1 LeafShi1 commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Fixes #15331

Root cause

Two issues in font-based autoscaling cause incorrect control bounds:

  1. The parent’s cached autoscale factor remains available after font-change processing completes. An inheriting container, such as DomainUpDown or NumericUpDown, can reuse that stale factor when its own font changes, unexpectedly scaling its location and width.
  2. Font-driven scaling skips all child container controls, assuming they will scale themselves when receiving the parent’s font-change notification. However, containers with an explicitly assigned font do not receive that notification unless required for DPI scaling. Consequently, resetting the form’s font leaves those controls at their previously scaled positions.

Proposed changes

  • Retain the parent’s autoscale factor only while processing and propagating a font change, restoring the previous factor afterward.
  • Remove the cached-factor mutation from the autoscale-factor getter.
  • Skip child containers during font-driven scaling only when they will receive a font-change notification and scale themselves.
  • Scale containers with explicit fonts, including their descendants, through the normal recursive scaling path while preserving DPI-specific notification handling.
  • Add regression coverage for both up-down controls, direct and nested parenting, inherited and explicit fonts, and different font-change/reset sequences.

Customer Impact

  • Prevents unexpected changes to the location and width of DomainUpDown and NumericUpDown when their fonts are changed after changing the form’s font.
  • Ensures that controls with explicit fonts participate in parent font-based layout scaling, allowing their location and width to return appropriately when the form’s font is reset.
  • Reduces manual layout correction after font edits in the WinForms Designer. No public API changes are introduced.

Regression?

  • Yes, it work well in .NET Framework

Risk

  • Minimal

Before

  • Changing an up-down control’s font after changing the form’s font can unexpectedly change its location and width.
  • If the up-down control has an explicit font, resetting the form’s font can leave it at its enlarged position. In the regression test, the control remains at (74,107) instead of returning to (40,50).
FontIssue.mp4

After

  • Changing the up-down control’s own font preserves its location and width.
  • Resetting the form’s font scales explicitly fonted up-down controls back to the expected location and width without clearing their explicit font.
AfterChanges.mp4

Test methodology

  • Add regression unit test
  • Manual test

Test environment(s)

  • .net 11.0.100-rc.3.26522.148
Microsoft Reviewers: Open in CodeFlow

@LeafShi1
LeafShi1 requested a review from a team as a code owner November 6, 2026 02:40
@codecov

codecov Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 39.79260%. Comparing base (8c48f24) to head (1f8d166).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@              Coverage Diff              @@
##                main      #15374   +/-   ##
=============================================
  Coverage   39.79260%   39.79260%           
=============================================
  Files            246         246           
  Lines           9836        9836           
  Branches        1036        1036           
=============================================
  Hits            3914        3914           
  Misses          5741        5741           
  Partials         181         181           
Flag Coverage Δ
Debug 39.79260% <ø> (ø)
production 42.31695% <ø> (ø)
test 19.92786% <ø> (ø)
unit 42.31695% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

Copilot was unable to run its full agentic suite in this review.

Copilot review overview

6 open issues
What changed in this PR

Updates WinForms font autoscaling behavior to correctly scale nested/inheriting container controls during parent font changes, while avoiding unintended scaling side-effects.

Changes:

  • Add unit tests covering font changes and autoscaling interactions for UpDownBase and ContainerControl.
  • Adjust ContainerControl font-change autoscaling to temporarily retain a scaling factor during propagation, then restore it.
  • Refine Control.ScaleChildControls to avoid double-scaling container controls that will scale via OnParentFontChanged, while still scaling containers with explicit fonts.
File Description
src/​test/​unit/​System.Windows.Forms/​System/​Windows/​Forms/​UpDownBaseTests.cs Adds regression coverage for UpDownBase bounds/width/location behavior when parent fonts change and fonts reset.
src/​test/​unit/​System.Windows.Forms/​System/​Windows/​Forms/​ContainerControlTests.cs Adds tests validating scaling of inheriting/nested containers across parent font changes and explicit font scenarios.
src/​System.Windows.Forms/​System/​Windows/​Forms/​Layout/​Containers/​ContainerControl.cs Changes how autoscale factor is retained/restored during OnFontChanged to support correct child scaling.
src/​System.Windows.Forms/​System/​Windows/​Forms/​Control.cs Updates child scaling logic to skip container controls that will handle scaling themselves, and modifies how causedByFontChanged is propagated.

Review effort: Lite

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Shyam-Gupta Shyam-Gupta left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. This is an important bug fix. Thanks.

@LeafShi1
LeafShi1 merged commit cbbfdec into main Nov 11, 2026
9 checks passed
@LeafShi1
LeafShi1 deleted the Fix_15331_Size_and_Location_of_UpDownControl_restore branch November 11, 2026 02:25
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DomainUpDown/NumericUpDown size and location cannot be restored after changing and resetting Font

4 participants