Improve Net11 TextBox text layout by reducing excess vertical whitespace - #14887
Improve Net11 TextBox text layout by reducing excess vertical whitespace#14887SimonZhao888 wants to merge 7 commits into
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. |



Root Cause
Under the Net11 modern style, inconsistencies have arisen in the calculations regarding the "external height contract" and the "internal available client area" for TextBox, ComboBox, and UpDown controls. On one hand, they retain the height semantics of classic single-line edit controls (Everett); on the other, they introduce a more aggressive modern "chrome/padding carve." This combination leads to two types of issues in scenarios involving small heights,
AutoSizesettings, or DPI/text scaling:Proposed changes
PreferredHeightCoreto the classic formula (maintaining compatibility with existing contracts); added a minimum single-line client height safeguard for the modern padding "carve" withinWM_NCCALCSIZE, and implemented tiered compression of the top/bottom carve based on border visibility to prevent the text area from being crushed.AutoSize/layout stability, minimum text measurement safeguards in DPI scenarios, and padding boundaries versus border visibility.Customer Impact
TableLayoutPanel—behave more predictably, with fewer visual jumps.Screenshots
Before
After
Scale 350%

Scale 300%

Scale 225%

Scale 150%

Scale 100%

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