Skip to content

Fixed the issue where text in controls such as TextBox and ComboBox was obscured at the bottom. - #14887

Merged
KlausLoeffelmann merged 24 commits into
dotnet:mainfrom
SimonZhao888:fix/textbox-display-whitespace
Sep 9, 2026
Merged

KlausLoeffelmann merged 24 commits into
dotnet:mainfrom
SimonZhao888:fix/textbox-display-whitespace

Conversation

@SimonZhao888

@SimonZhao888 SimonZhao888 commented Aug 13, 2026 •

Copy link
Copy Markdown
Member

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:

  • Text descenders could be clipped at specific DPI settings.
  • Editable ComboBox controls expanded the native EDIT child without vertically repositioning it, leaving the text visually top-aligned.
  • DropDown and DropDownList used inconsistent height calculations.
  • Native font metrics may differ by one device pixel depending on handle-creation order.
  • UpDown buttons and glyphs were disproportionate to the updated control height.

Proposed changes

  • Refine shared Net11 field padding and preferred-height calculations to reduce excess whitespace while preserving sufficient text space.
  • Update modern TextBox non-client layout, border rendering, and high-DPI scrolling behavior.
  • Make ComboBox styles use consistent preferred-height calculations.
  • Vertically center the editable ComboBox EDIT child while retaining a font-safe height to prevent descender clipping.
  • Keep DropDownList text vertically centered through managed rendering.
  • Adjust UpDown control button layout and arrow glyph proportions.
  • Add regression coverage across multiple DPI settings, font changes, handle recreation, property-order changes, padding, and ComboBox styles.
  • Allow the native EDIT rectangle a one-device-pixel rounding tolerance while continuing to verify its visual center and all other geometry strictly.

Customer Impact

  • Reduces excessive vertical whitespace in modern single-line input controls.
  • Prevents text and descender clipping across supported DPI settings.
  • Keeps editable ComboBox text visually centered from 100% through 300% DPI.
  • Provides more consistent control heights and alignment in forms and auto-sized layouts.
  • Improves NumericUpDown and DomainUpDown button proportions.
  • Does not change public APIs or classic visual-style behavior; changes are limited to intended Net11 visual and layout corrections.

Screenshots

Before

image

After

Scale 350%
image

Scale 300%
image

Scale 250%
image

Scale 225%
image

Scale 200%
image

Scale 175%
image

Scale 150%
image

Scale 125%
image

Scale 100%
image

Test methodology

  • Manually
  • Automated test cases

Test environment(s)

  • 11.0.0-preview.7.26381.103
Microsoft Reviewers: Open in CodeFlow

@SimonZhao888

Copy link
Copy Markdown
Member Author

Issue 1

When the screen scale is set to 225% or higher, text within TextBox and NumericUpDown controls under .NET 11 is not fully displayed; parts of the text are obscured by the bottom border.
image

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.

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 PreferredHeight behavior with the classic (Everett) preferred-height formula.
  • Add single-line client-area carve adjustments during WM_NCCALCSIZE to 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.

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.

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)
        };

@KlausLoeffelmann

KlausLoeffelmann commented Aug 14, 2026 •

Copy link
Copy Markdown
Member

There is the issue, which I think also Copilot pointed out in the reviews (at least it is slightly related), that the system-reservation of the Padding will probably be scaleing-up badly.

And, I think that is already the case, because if you watch closely, you see that the TextBox' inner native rectangle is reaching just slightly in our rounded border.

image

Let's make the rounded rectangle more edgy - and see how that looks. If you reduce the radius, the edges become steeper, and it might also mitigate the bad anti-alias of the rounded rectangle better. And I think we can reduce the radius here considerably.

image

@SimonZhao888

Copy link
Copy Markdown
Member Author

And, I think that is already the case, because if you watch closely, you see that the TextBox' inner native rectangle is reaching just slightly in our rounded border.

Done.

Simon Zhao (BEYONDSOFT CONSULTING INC) added 2 commits August 17, 2026 10:16
Simon Zhao (BEYONDSOFT CONSULTING INC) added 2 commits August 18, 2026 15:15
…nner and more consistent across common DPI settings, mitigating the visual issue where rounded corners appear thicker than straight lines.
@dotnet-policy-service dotnet-policy-service Bot removed the waiting-author-feedback The team requires more information from the author label Sep 4, 2026
@SimonZhao888 SimonZhao888 added draft draft PR and removed waiting-review This item is waiting on review by one or more members of team labels Sep 4, 2026
@SimonZhao888 SimonZhao888 added waiting-review This item is waiting on review by one or more members of team and removed draft draft PR labels Sep 4, 2026
@codecov

codecov Bot commented Sep 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 37.24166%. Comparing base (0e26835) to head (5258c55).
⚠️ Report is 6 commits behind head on main.

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           
Flag Coverage Δ
Debug 37.24166% <ø> (ø)
production 39.36526% <ø> (ø)
test 20.64923% <ø> (ø)
unit 39.36526% <ø> (ø)

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.

@KlausLoeffelmann KlausLoeffelmann 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 to me - let's take this!

@KlausLoeffelmann
KlausLoeffelmann merged commit 3248f2c into dotnet:main Sep 9, 2026
8 checks passed
@dotnet-policy-service dotnet-policy-service Bot removed the waiting-review This item is waiting on review by one or more members of team label Sep 9, 2026
@LeafShi1

Copy link
Copy Markdown
Member

/backport to release/11.0

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0 (link to workflow run)

@github-actions

Copy link
Copy Markdown
Contributor

@LeafShi1 backporting to release/11.0 failed, the patch most likely resulted in conflicts. Please backport manually!

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

Link to workflow output

ricardobossan pushed a commit to ricardobossan/winforms that referenced this pull request Sep 11, 2026
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.
KlausLoeffelmann pushed a commit that referenced this pull request Sep 12, 2026
…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]>
LeafShi1 pushed a commit that referenced this pull request Sep 15, 2026
…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]>
LeafShi1 added a commit that referenced this pull request Sep 15, 2026
…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)
@SimonZhao888
SimonZhao888 deleted the fix/textbox-display-whitespace branch September 17, 2026 01:24
KlausLoeffelmann added a commit that referenced this pull request Sep 21, 2026
…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
@LeafShi1 LeafShi1 modified the milestones: .NET 11, 11.0-rc2 Sep 22, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TextBox and ComboBox are too tall in Net11 visual styles Up/Down buttons of the DomainUpDown/NumericUpDown control scale incorrectly at different DPI

5 participants