Repository navigation
Fixed the issue where text in controls such as TextBox and ComboBox was obscured at the bottom. - #14887
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refines single-line TextBox layout under VisualStylesMode.Net11 by reducing excess vertical whitespace and stabilizing the text-to-border geometry while keeping classic compatibility expectations.
Changes:
- Align modern
PreferredHeightbehavior with the classic (Everett) preferred-height formula. - Add single-line client-area carve adjustments during
WM_NCCALCSIZEto prevent overly large vertical padding from shrinking the usable text area. - Update/add unit tests to assert the new preferred-height and non-client/client-area behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/System.Windows.Forms/System/Windows/Forms/Controls/TextBox/TextBoxBase.cs | Changes modern preferred-height selection and adjusts single-line padding carve logic in WM_NCCALCSIZE. |
| src/test/unit/System.Windows.Forms/TextBoxBaseTests.cs | Updates existing tests and adds regression tests for preferred height, padding, and border/non-client behavior in Net11 mode. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…UpDown controls under different scaling settings.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.
Suppressed comments (2)
src/test/unit/System.Windows.Forms/TextBoxBaseTests.cs:226
- The minimum client-height assertion uses a hard-coded "+ 3" pixels, which can be incorrect when the test is executed under non-96 DPI. The production code scales this margin with DPI (LogicalToDeviceUnits/ScaleToDpi), so the test should scale the 3px term as well to avoid DPI-dependent failures.
Assert.True(control.ClientSize.Height >= control.Font.Height + 3);
src/test/unit/System.Windows.Forms/TextBoxBaseTests.cs:246
- This pixel-based border assertion may be flaky because the control BackColor is set to White, which can match the rendered border color in some themes/high-contrast configurations. Using an uncommon BackColor reduces the chance of accidental equality while still validating that the top/bottom border pixels are not client-filled.
BackColor = Color.White,
ForeColor = Color.Black,
Size = new Size(120, s_preferredHeight)
};
Done. |
…nner and more consistent across common DPI settings, mitigating the visual issue where rounded corners appear thicker than straight lines.
3391db9 to
f184e24
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #14887 +/- ##
=============================================
Coverage 37.24166% 37.24166%
=============================================
Files 246 246
Lines 9774 9774
Branches 1029 1029
=============================================
Hits 3640 3640
Misses 5970 5970
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.
Looks good to me - let's take this!
|
/backport to release/11.0 |
|
Started backporting to |
|
@LeafShi1 backporting to git am output$ git cherry-pick 3248f2c4b8839706952bb7d863a0b2b957b745f7
Auto-merging src/System.Windows.Forms/System/Windows/Forms/Controls/ComboBox/ComboBox.Modern.cs
CONFLICT (content): Merge conflict in src/System.Windows.Forms/System/Windows/Forms/Controls/ComboBox/ComboBox.Modern.cs
Auto-merging src/System.Windows.Forms/System/Windows/Forms/Controls/ComboBox/ComboBox.ModernComboAdapter.cs
Auto-merging src/System.Windows.Forms/System/Windows/Forms/Controls/TextBox/TextBoxBase.cs
Auto-merging src/System.Windows.Forms/System/Windows/Forms/Controls/UpDown/UpDownBase.cs
Auto-merging src/System.Windows.Forms/System/Windows/Forms/Rendering/ModernControlVisualStyles.cs
Auto-merging src/test/unit/System.Windows.Forms/System/Windows/Forms/ComboBoxTests.cs
CONFLICT (content): Merge conflict in src/test/unit/System.Windows.Forms/System/Windows/Forms/ComboBoxTests.cs
error: could not apply 3248f2c4b... Fixed the issue where text in controls such as TextBox and ComboBox was obscured at the bottom. (#14887)
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch
Applying: Improve Net11 TextBox text layout by reducing excess vertical whitespace
Applying: Handling the issue of incomplete text display for TextBox and NumericUpDown controls under different scaling settings.
Applying: Adjust the height of the ComboBox control in .NET 1.1.
Applying: Adjusting the radian angle of a text box in Net11 mode
Applying: Adjust the outer border length of controls like UpDown to minimize the native TextBox's impact on the border.
Applying: Handle the failed test cases
Applying: Handle Copilot feedback
Applying: Ensure the borders of Net11 Modern rounded-corner controls remain thinner and more consistent across common DPI settings, mitigating the visual issue where rounded corners appear thicker than straight lines.
Applying: Handle failure test cases
Applying: Increase the bottom height of textbox when the control is focused.
Applying: The height of controls like Edit in Net11 mode has been readjusted so that it is no longer the same as the height of controls in Classic mode.
Applying: Adjust the size of the DataGridViewComboBoxCell; adjust the size of the UpDown control buttons.
Applying: Fixed an issue where text was obscured at certain scales.
Applying: Remove empty line
Applying: Fixed the issue of inconsistent height of ComboBox when DropDownStyle=DropDown and DropDownList.
Applying: Fixed an issue where the initial horizontal scroll position was incorrect at 350% DPI, causing the first character to be cut off.
Applying: Handle conflicts
Applying: Fix issue: ComboBox text appears vertically misaligned in DropDown mode, repro on all DPI values: 100%DPI ~ 300%DPI
Applying: Remove DataGridView related fixes
Applying: Handle failure test case
Applying: Handle conflicts
Using index info to reconstruct a base tree...
M src/test/unit/System.Windows.Forms/System/Windows/Forms/ComboBoxTests.cs
Falling back to patching base and 3-way merge...
Auto-merging src/test/unit/System.Windows.Forms/System/Windows/Forms/ComboBoxTests.cs
CONFLICT (content): Merge conflict in src/test/unit/System.Windows.Forms/System/Windows/Forms/ComboBoxTests.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0021 Handle conflicts
Error: The process '/usr/bin/git' failed with exit code 128 |
Layer the dotnet#14919 stroke updates onto the rendering work introduced by dotnet#14887. Select outline colors according to the active control state, bring back hover cues for Net11, and animate focus with a narrowing underline. Cover the resolver with tests and update TextBoxBase, ComboBox, and UpDownBase to follow the field-based stroke design.
…as obscured at the bottom. (#14887) * Improve Net11 TextBox text layout by reducing excess vertical whitespace * Handling the issue of incomplete text display for TextBox and NumericUpDown controls under different scaling settings. * Adjust the height of the ComboBox control in .NET 1.1. * Adjusting the radian angle of a text box in Net11 mode * Adjust the outer border length of controls like UpDown to minimize the native TextBox's impact on the border. * Handle the failed test cases * Handle Copilot feedback * Ensure the borders of Net11 Modern rounded-corner controls remain thinner and more consistent across common DPI settings, mitigating the visual issue where rounded corners appear thicker than straight lines. * Handle failure test cases * Increase the bottom height of textbox when the control is focused. * The height of controls like Edit in Net11 mode has been readjusted so that it is no longer the same as the height of controls in Classic mode. * Adjust the size of the DataGridViewComboBoxCell; adjust the size of the UpDown control buttons. * Fixed an issue where text was obscured at certain scales. * Remove empty line * Fixed the issue of inconsistent height of ComboBox when DropDownStyle=DropDown and DropDownList. * Fixed an issue where the initial horizontal scroll position was incorrect at 350% DPI, causing the first character to be cut off. * Handle conflicts * Fix issue: ComboBox text appears vertically misaligned in DropDown mode, repro on all DPI values: 100%DPI ~ 300%DPI * Remove DataGridView related fixes * Handle failure test case * Handle conflicts --------- Authored-by: Simon Zhao (BEYONDSOFT CONSULTING INC) <[email protected]>
…as obscured at the bottom. (#14887) * Improve Net11 TextBox text layout by reducing excess vertical whitespace * Handling the issue of incomplete text display for TextBox and NumericUpDown controls under different scaling settings. * Adjust the height of the ComboBox control in .NET 1.1. * Adjusting the radian angle of a text box in Net11 mode * Adjust the outer border length of controls like UpDown to minimize the native TextBox's impact on the border. * Handle the failed test cases * Handle Copilot feedback * Ensure the borders of Net11 Modern rounded-corner controls remain thinner and more consistent across common DPI settings, mitigating the visual issue where rounded corners appear thicker than straight lines. * Handle failure test cases * Increase the bottom height of textbox when the control is focused. * The height of controls like Edit in Net11 mode has been readjusted so that it is no longer the same as the height of controls in Classic mode. * Adjust the size of the DataGridViewComboBoxCell; adjust the size of the UpDown control buttons. * Fixed an issue where text was obscured at certain scales. * Remove empty line * Fixed the issue of inconsistent height of ComboBox when DropDownStyle=DropDown and DropDownList. * Fixed an issue where the initial horizontal scroll position was incorrect at 350% DPI, causing the first character to be cut off. * Handle conflicts * Fix issue: ComboBox text appears vertically misaligned in DropDown mode, repro on all DPI values: 100%DPI ~ 300%DPI * Remove DataGridView related fixes * Handle failure test case * Handle conflicts --------- Authored-by: Simon Zhao (BEYONDSOFT CONSULTING INC) <[email protected]>
…x controls (#15106) Replays #14887 onto the corrected integration/11.0-RC2 branch based on release/11.0. This is prerequisite 8 of 11 in the ordered RC2 integration chain. ###### Microsoft Reviewers: [Open in CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/dotnet/winforms/pull/15106)
…5143) ## Description Backport the selected .NET 11 Visual Styles fixes to release/11.0 for RC2. This PR consolidates the following previously reviewed fixes into a single backport: - #14853 - Fix editable control border color in NET11 visual styles - #14904 - Fix modern RadioButton glyph clipping in RTL layouts - #14910 - Fix GroupBox background image rendering in .NET 11 visual styles - #14865 - Fix CheckBox and RadioButton explicit BackColor handling in VisualStylesMode.Net11 - #14860 - Fix Button focus indicator when hosted on a TabPage - #14827 - Fix ComboBox rendering with DropDownStyle.Simple - #15019 - Fix setting VisualStylesMode to Classic in the Properties window - #14887 - Fix text clipping in controls such as TextBox and ComboBox - #14929 - Fix inherited ForeColor/BackColor updates for controls inside GroupBox - #14815 - Fix ToggleSwitch text overlap in RTL layouts - #15033 - Disable NET11 VisualStylesMode for composite controls until their layout modernization is completed - #15113 - Reinstate per\-state Net11 editable\-control border strokes - #15159 - Fix CheckBox and RadioButton render transparently over a parent GroupBox BackgroundImage in VisualStylesMode.Net11 - #15163 - Add design-time analyzer guardrails and shared analyzer test harness ## Customer Impact - Without these fixes, applications using the .NET 11 Visual Styles may encounter rendering, layout, color, RTL, and design\-time issues across several WinForms controls, including TextBox, ComboBox, Button, CheckBox, RadioButton, GroupBox, and ToggleSwitch. The changes also prevent NET11 VisualStylesMode from being applied to composite controls that are not yet ready for the new visual style behavior. - The design-time analyzer guardrails detect unsupported Designer-generated code patterns that can break designer loading or serialization, and provide actionable guidance without changing application runtime behavior. Individual diagnostics remain configurable. ## Regression Most of the changes in this backport address regressions or incorrect behavior identified during .NET 11 Visual Styles development and validation. #15113 introduces the updated per-state border styling for editable controls as part of the .NET 11 Visual Styles. The remaining changes fix rendering, layout, color, RTL, and design-time issues related to the new visual styles. #15163 does not address a shipped runtime regression. It introduces design-time analyzer guardrails and includes fixes for analyzer false positives, missed cases, and VB analyzer exceptions identified during development. The individual changes have been reviewed and validated in their original PRs, and the selected changes were also tested before this backport. ## Testing Each fix includes its corresponding tests and validation from the original PR. The selected fixes were also tested together to validate the combined RC2 changes before backporting them to release/11.0. ### Risk **Medium.** - The primary risk is in WinForms control rendering and layout under the .NET 11 Visual Styles, along with the newly added design\-time analyzer behavior. This backport includes both visual-style fixes and an intentional visual behavior change for editable\-control borders introduced by #15113. The affected areas include: - Editable control border rendering and state-specific border styling. - CheckBox and RadioButton colors, glyphs, and background rendering. - RTL layout for RadioButton and ToggleSwitch. - GroupBox background, color inheritance, and child-control rendering. - Button focus indicator rendering. - ComboBox layout and rendering. - Text layout and clipping in editable controls. - VisualStylesMode behavior at design time. - VisualStylesMode availability for composite controls. - Design-time analyzer diagnostics. Some diagnostics are enabled as errors by default and can fail builds containing unsupported Designer-generated code. The diagnostics remain individually configurable. The individual changes have been reviewed and validated in their original PRs, and the combined changes were tested together before this backport. ## Fix Backport the selected .NET 11 Visual Styles changes for RC2, including: - Introduce the new per-state border styling for editable controls. - Fix editable-control border colors and text rendering. - Fix CheckBox, RadioButton, and ToggleSwitch rendering, including RTL scenarios. - Fix GroupBox background rendering and inherited colors. - Fix Button focus indicator rendering. - Fix ComboBox layout and rendering. - Fix VisualStylesMode configuration in the Properties window. - Disable NET11 VisualStylesMode for composite controls that are not yet ready for the new visual styles. - Adds design-time analyzer guardrails and the shared analyzer test infrastructure



Fixes #14938
Root Cause
In VisualStylesMode.Net11, single-line input controls inherited excessive vertical padding and chrome metrics, making TextBox, ComboBox, and UpDown-based controls unnecessarily tall. Reducing that space exposed additional native-control layout issues:
Proposed changes
Customer Impact
Screenshots
Before
After
Scale 350%

Scale 300%

Scale 250%

Scale 225%

Scale 200%

Scale 175%

Scale 150%

Scale 125%

Scale 100%

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