Skip to content

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

Open
SimonZhao888 wants to merge 24 commits into
dotnet:mainfrom
SimonZhao888:fix/textbox-display-whitespace
Open

Fixed the issue where text in controls such as TextBox and ComboBox was obscured at the bottom.#14887
SimonZhao888 wants to merge 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.

Comment thread src/test/unit/System.Windows.Forms/TextBoxBaseTests.cs Outdated
…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.
Simon Zhao (BEYONDSOFT CONSULTING INC) added 2 commits August 26, 2026 17:43
… that it is no longer the same as the height of controls in Classic mode.
@SimonZhao888 SimonZhao888 changed the title Improve Net11 TextBox text layout by reducing excess vertical whitespace Fixed the issue where text in controls such as TextBox and ComboBox was obscured at the bottom. Aug 27, 2026
@SimonZhao888
SimonZhao888 force-pushed the fix/textbox-display-whitespace branch from b8935dc to ecc17db Compare August 28, 2026 09:02
…de, repro on all DPI values: 100%DPI ~ 300%DPI
Comment thread src/System.Windows.Forms/System/Windows/Forms/Controls/ComboBox/ComboBox.cs Outdated
@SimonZhao888 SimonZhao888 added the waiting-review This item is waiting on review by one or more members of team label Sep 2, 2026
Comment thread src/test/unit/System.Windows.Forms/System/Windows/Forms/ComboBoxTests.cs Outdated
@dotnet-policy-service dotnet-policy-service Bot added the waiting-author-feedback The team requires more information from the author label Sep 4, 2026
@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-review This item is waiting on review by one or more members of team

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