Repository navigation
Fix UpDown buttons scaling incorrectly on DPI changes - #15207
SimonZhao888 merged 3 commits into
Conversation
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The implementation leaves button layout stale, overrides supported custom heights, and lacks regression coverage.
Review effort: Balanced
Findings: 1
Open (2)
What changed in this PR
Updates UpDownBase DPI/font handling to recalculate control and button dimensions.
Changes:
- Adds parent-font-change scaling logic.
- Records the protected override in the public API baseline.
| File | Description |
|---|---|
UpDownBase.cs |
Recalculates height and button width. |
PublicAPI.Unshipped.txt |
Adds the new override signature. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15207 +/- ##
=============================================
Coverage 37.84861% 37.84861%
=============================================
Files 246 246
Lines 9789 9789
Branches 1031 1031
=============================================
Hits 3705 3705
Misses 5920 5920
Partials 164 164
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
KlausLoeffelmann
left a comment
There was a problem hiding this comment.
Yes.
Let's please also backport this to .NET 11 - because it can screw up layout and cascade things up on for example A11Y TextSize changes.
* Fix UpDown buttons scaling incorrectly on DPI changes * Addoverride System.Windows.Forms.UpDownBase.OnParentFontChanged 同PublicAPI * Add unit test
…5386) ## Description Backports seven WinForms fixes from main to release/11.0 for inclusion in the December 2026 .NET 11 servicing release. These changes address several issues affecting control rendering, layout, DPI scaling, selection handling, and native resource management. ## Fixes - #15325 - #15212 - #15361 - #15270 - #15207 - #15254 - #15390 ## Proposed Changes This PR cherry-picks the following fixes: 1. **UpDown sizing and focus indicator (#15325)** - Fixes sizing issues and focus-indicator flickering in UpDown controls when using .NET 11 visual styles. 2. **DomainUpDown and NumericUpDown height (#15212)** - Fixes an issue where these controls incorrectly allow height changes instead of preserving their expected height in VisualStylesMode.Net11. 3. **ListBox selection handling (#15361)** - Fixes an IndexOutOfRangeException in ListBox.RefreshItems caused by a stale selected-item count cache. 4. **ToggleSwitch checked thumb color (#15270)** - Corrects the checked thumb color in both light and dark modes. 5. **UpDown DPI scaling (#15207)** - Fixes incorrect scaling of UpDown buttons when DPI changes. 6. **Bitmap native memory leak (#15254)** - Fixes a native GDI+ memory leak when a Bitmap is finalized during Image.Save(Stream, ImageFormat). 7. **ToggleSwitch animation improvements** - Shortens ToggleSwitch state-transition animations to improve responsiveness. ## Customer Impact These fixes address issues that can affect applications running on .NET 11: - **Visual and layout issues:** Incorrect control sizing, focus-indicator flickering, and inconsistent ToggleSwitch rendering can negatively affect the user experience. - **High-DPI environments:** UpDown buttons may scale incorrectly when applications move between displays with different DPI settings. - **Application reliability:** The ListBox issue can cause an IndexOutOfRangeException during item refresh operations. - **Resource management:** The Bitmap issue can cause native GDI+ memory to remain allocated after the affected save operation. The changes improve control rendering, layout consistency, DPI scaling, and application reliability. Existing applications will receive the fixes without requiring code changes. Some visual and behavioral differences may be noticeable in affected controls, particularly those using .NET 11 visual styles. ## Regression? **Partially.** Several fixes address issues associated with the new .NET 11 visual styles, particularly control sizing, focus indicators, and ToggleSwitch rendering. The remaining fixes address functional correctness, DPI scaling, and native resource management issues. Not all seven issues have been confirmed as regressions introduced in .NET 11. ## Testing All seven included fixes have been validated. - Verified the fixes for all seven cherry-picked PRs. - Confirmed that the corresponding GitHub issues are resolved. - No new regression issues were identified during validation. ## Risk **Minimal** - These changes have already been merged into main. - All seven fixes have been individually validated. - No new regressions were identified during testing. - Most changes are targeted fixes for specific control behaviors. - The ListBox and Bitmap fixes affect functional behavior and native resource management, therefore, additional regression tests have been added.


Fixes #14784
Proposed changes
Update
UpDownBase.OnParentFontChangedto:PreferredHeight._defaultButtonsWidthbased on the current device DPI.Customer Impact
DomainUpDownandNumericUpDowncan be incorrectly sized after changing the display scaling or moving the application between monitors with different DPI settings.Regression?
Risk
Screenshots
Before
The Up/Down buttons could scale incorrectly after a DPI change. For example, the buttons could become larger when scaling down or smaller when scaling up.
Recording.2026-07-20.021407.mp4
After
The control height and default buttons width are recalculated after the parent font changes, and the Up/Down buttons scale correctly with the current DPI.
AfterChanges.mp4
Test methodology
Test environment(s)
Microsoft Reviewers: Open in CodeFlow