Skip to content

Commit 69aa55b

Browse files
authored
Fix GroupBox Standard and Popup layout overlap when switching to NET11 visual styles (#14891)
## 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: - Preserve Classic layout metrics for Standard and Popup GroupBoxes in NET11 mode. - Preserve caption font settings while respecting system text scaling. - Keep the modern Popup appearance with an accent-colored header and border. - Leave Flat GroupBox behavior unchanged. - Add regression tests and update documentation.
1 parent d66f735 commit 69aa55b

7 files changed

Lines changed: 328 additions & 283 deletions

File tree

docs/net11-visualstyles-layout-guidance.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,11 @@ serialized only when it differs from `Padding.Empty`.
180180

181181
## Account for GroupBox DisplayRectangle
182182

183-
In modern `FlatStyle.Standard`, the GroupBox caption sits above a borderless rectangular surface. Its
184-
`DisplayRectangle` starts lower than the classic etched-frame rectangle and reserves more content space above
185-
than below. The caption aligns with the control Padding. Docked and anchored children are relaid out against the
186-
new rectangle.
183+
In modern `FlatStyle.Standard` and `FlatStyle.Popup`, the GroupBox caption sits above a modern surface while
184+
the `DisplayRectangle` preserves the classic etched-frame rectangle. `FlatStyle.Popup` uses a subtle
185+
accent-tinted header band and accent border to distinguish the header without changing the content rectangle.
186+
The caption aligns with the control Padding, and existing child layouts remain stable when switching visual
187+
styles.
187188

188189
Use the GroupBox as a real layout container:
189190

@@ -207,12 +208,10 @@ TableLayoutPanel addressTable = new()
207208
addressGroup.Controls.Add(addressTable);
208209
```
209210

210-
Avoid positioning children with a fixed Y offset derived from `Font.Height`. The renderer owns caption metrics,
211-
and `DisplayRectangle` is the supported content boundary.
211+
Avoid positioning children outside `DisplayRectangle`; it remains the supported content boundary.
212212

213-
The modern caption is derived from the ambient font at paint time. Standard and Popup enlarge the caption; Flat
214-
keeps the ambient size. If the ambient font is regular and a matching installed Semibold family exists, WinForms
215-
uses that real face. Otherwise the ambient weight is preserved; already styled fonts are never promoted.
213+
The modern caption is derived from the ambient font at paint time. WinForms preserves the ambient font family,
214+
size, and style while still following system text scale.
216215

217216
## React to live text-scale changes
218217

src/System.Windows.Forms/System/Windows/Forms/Controls/GroupBox/GroupBox.FlatStyle.Docs.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@ public partial class GroupBox
1313
/// <remarks>
1414
/// <para>
1515
/// In an effective .NET 11-or-later mode, <see cref="FlatStyle.Standard"/> renders a borderless rectangular
16-
/// surface with an enlarged caption, <see cref="FlatStyle.Flat"/> renders a rounded accent outline with an
17-
/// ambient-size inline caption, and <see cref="FlatStyle.Popup"/> renders a Windows-accent header band.
16+
/// surface, <see cref="FlatStyle.Flat"/> renders a rounded accent outline, and <see cref="FlatStyle.Popup"/>
17+
/// renders a rounded accent outline with a subtle accent-tinted header band.
1818
/// <see cref="FlatStyle.System"/> remains a native <c>BS_GROUPBOX</c> in every mode.
1919
/// </para>
2020
/// <para>
21-
/// The modern Standard surface intentionally moves <see cref="Control.DisplayRectangle"/> down and reserves
22-
/// more space above its content than below. Its caption aligns with <see cref="Control.Padding"/>. When the
23-
/// ambient font is regular and a matching installed Semibold family exists, modern captions use that real
24-
/// face; otherwise they preserve the ambient weight. AutoSize layouts remeasure automatically. See the
21+
/// The modern Standard and Popup surfaces preserve the classic <see cref="Control.DisplayRectangle"/> so
22+
/// existing child layouts remain stable when switching visual styles. Modern captions preserve the ambient
23+
/// font family, size, and style while still following system text scale. See the
2524
/// <see href="https://github.com/dotnet/winforms/blob/main/docs/net11-visualstyles-layout-guidance.md">
2625
/// .NET 11 VisualStyles layout guidance</see>.
2726
/// </para>

0 commit comments

Comments
 (0)