Fix GroupBox Standard and Popup layout overlap when switching to NET11 visual styles - #14891
Draft
LeafShi1 wants to merge 1 commit into
Draft
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts modern GroupBox rendering/layout in .NET 11 visual styles to prevent child-control overlap when switching VisualStylesMode from Classic to Net11, by keeping DisplayRectangle stable for FlatStyle.Standard and FlatStyle.Popup.
Changes:
- Preserve classic
DisplayRectanglemetrics for modern Standard/Popup and treat Classic→Net11 as repaint-only (no metrics relayout) for those styles. - Update modern caption behavior to preserve the ambient font family/size/style while still applying system text scale.
- Refresh Popup’s modern appearance (subtle accent-tinted header band + accent border) and update tests/docs accordingly.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/test/unit/System.Windows.Forms/System/Windows/Forms/GroupBoxTests.cs | Updates/extends unit tests for mode-switch layout stability, caption font behavior, and Popup rendering expectations. |
| src/System.Windows.Forms/System/Windows/Forms/Rendering/ModernControlVisualStyles.cs | Removes now-unused GroupBox-related modern constants. |
| src/System.Windows.Forms/System/Windows/Forms/Controls/GroupBox/GroupBox.Modern.cs | Implements classic-metrics padding for modern Standard/Popup, updates caption font creation, and tweaks Popup header rendering. |
| src/System.Windows.Forms/System/Windows/Forms/Controls/GroupBox/GroupBox.FlatStyle.Docs.cs | Updates XML docs to reflect preserved DisplayRectangle and new Popup appearance. |
| src/System.Windows.Forms/System/Windows/Forms/Controls/GroupBox/GroupBox.cs | Refactors DisplayRectangle to use a cached DisplayFontHeight helper and aligns modern/classic calculations. |
| docs/net11-visualstyles-layout-guidance.md | Updates layout guidance to reflect preserved Standard/Popup content rectangle and revised caption/font guidance. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
298
to
+305
| Color bodyColor = BackColor.A == 0 | ||
| ? Color.Transparent | ||
| : BackColor; | ||
| Color headerColor = Application.SystemVisualSettings.AccentColor; | ||
| Color headerSurfaceColor = PopupButtonColorMath.Blend( | ||
| bodyColor, | ||
| headerColor, | ||
| PopupHeaderAccentBlendAmount); |
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.
Fixes #14832
Root Cause
GroupBoxused larger NET11 caption/header metrics forDisplayRectangleinFlatStyle.StandardandFlatStyle.Popup.After switching from Classic to NET11, the content rectangle moved, but existing child controls kept their positions. This made controls near the top overlap the GroupBox header/border.
Proposed changes
Update modern GroupBox rendering and layout so that:
Customer Impact
Regression?
Risk
Screenshots
Before
Switching Classic → NET11 could change the GroupBox content area and cause top child controls to overlap the header/border.
After
Standard and Popup GroupBoxes keep the same content area after switching to NET11, so child controls stay in place and no longer overlap.
Test methodology
Test environment(s)
Microsoft Reviewers: Open in CodeFlow