Skip to content

Fix GroupBox Standard and Popup layout overlap when switching to NET11 visual styles - #14891

Draft
LeafShi1 wants to merge 1 commit into
dotnet:mainfrom
LeafShi1:Fix_14832_Child_controls_overlap_the_GroupBox_border
Draft

Fix GroupBox Standard and Popup layout overlap when switching to NET11 visual styles#14891
LeafShi1 wants to merge 1 commit into
dotnet:mainfrom
LeafShi1:Fix_14832_Child_controls_overlap_the_GroupBox_border

Conversation

@LeafShi1

@LeafShi1 LeafShi1 commented Aug 14, 2026

Copy link
Copy Markdown
Member

Fixes #14832

Root Cause

GroupBox used larger NET11 caption/header metrics for DisplayRectangle in FlatStyle.Standard and FlatStyle.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:

  • FlatStyle.Standard and FlatStyle.Popup preserve the Classic DisplayRectangle metrics.
  • Switching Standard/Popup GroupBoxes from Classic to NET11 no longer requests metric relayout.
  • Modern captions preserve the ambient font family, size, and style, while still respecting system text scale.
  • FlatStyle.Popup keeps a distinct modern appearance using a subtle accent-tinted header band and accent border.
  • FlatStyle.Flat keeps its modern outline metrics, since its layout is tied to the baseline outline renderer.
  • Tests are updated to cover Classic-to-NET11 DisplayRectangle stability, docked child stability, caption font preservation, and Popup header rendering.
  • GroupBox layout guidance/docs are updated to describe the preserved content rectangle and modern Popup appearance.

Customer Impact

  • Apps can enable or switch to NET11 visual styles with less layout disruption. Existing GroupBox child layouts remain stable for Standard and Popup styles.

Regression?

  • No

Risk

  • Minimal

Screenshots

Before

Switching Classic → NET11 could change the GroupBox content area and cause top child controls to overlap the header/border.

Image

After

Standard and Popup GroupBoxes keep the same content area after switching to NET11, so child controls stay in place and no longer overlap.

image

Test methodology

  • Unit test and manually

Test environment(s)

  • .net 11.0.0-rc.1.26411.119
Microsoft Reviewers: Open in CodeFlow

@LeafShi1
LeafShi1 requested a review from a team as a code owner August 14, 2026 10:00
@LeafShi1
LeafShi1 requested a lite review from Copilot August 14, 2026 10:01
@LeafShi1
LeafShi1 marked this pull request as draft August 14, 2026 10:04

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 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 DisplayRectangle metrics 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);
@dotnet-policy-service dotnet-policy-service Bot added the draft draft PR label Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

draft draft PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Child controls overlap the GroupBox border for Standard and Popup styles after switching VisualStylesMode from Classic to NET11

2 participants