Improve Net11 TextBox text layout by reducing excess vertical whitespace - #14887
Open
SimonZhao888 wants to merge 5 commits into
Open
Improve Net11 TextBox text layout by reducing excess vertical whitespace#14887SimonZhao888 wants to merge 5 commits into
SimonZhao888 wants to merge 5 commits into
Conversation
Member
Author
SimonZhao888
requested review from
KlausLoeffelmann,
LeafShi1,
Shyam-Gupta and
ricardobossan
August 13, 2026 07:44
Contributor
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.
Comment on lines
+255
to
+258
| Color topCenter = bitmap.GetPixel(bitmap.Width / 2, 0); | ||
| Color bottomCenter = bitmap.GetPixel(bitmap.Width / 2, bitmap.Height - 1); | ||
| Assert.NotEqual(control.BackColor.ToArgb(), topCenter.ToArgb()); | ||
| Assert.NotEqual(control.BackColor.ToArgb(), bottomCenter.ToArgb()); |
Comment on lines
+2505
to
+2507
| int clientHeight = clientRect.bottom - clientRect.top; | ||
| int minimumSingleLineClientHeight = FontHeight + LogicalToDeviceUnits(3); | ||
| int maxVerticalCarve = Math.Max(0, clientHeight - minimumSingleLineClientHeight); |
…UpDown controls under different scaling settings.
Contributor
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)
};
Member
added 3 commits
August 14, 2026 11:08
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Root Cause
Under
VisualStylesMode.Net11, theTextBoxemploys a new rendering model featuring rounded corners and a modern border style; however, the usable text area of single-line text boxes remains subject to the combined influence of legacy height-compatibility formulas and modern padding "carve" logic. The superposition of these two measurement models results in uneven padding distribution—particularly in the vertical dimension:Consequently, the primary objective of this modification is to standardize the geometric relationship between the text area and the border in
Net11mode, reduce unnecessary whitespace, and ensure more consistent behavior for single-lineTextBoxcontrols across various border styles and scaling levels.Proposed changes
Customer Impact
Screenshots
Before
After
Scale 350%

Scale 300%

Scale 225%

Scale 150%

Scale 100%

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