Skip to content

Fix ToggleSwitch focus border rendering for CheckBox and RadioButton - #14990

Open
LeafShi1 wants to merge 3 commits into
dotnet:mainfrom
LeafShi1:Fix_14886_checkbox/radiobutton_focus_rectangle
Open

Fix ToggleSwitch focus border rendering for CheckBox and RadioButton#14990
LeafShi1 wants to merge 3 commits into
dotnet:mainfrom
LeafShi1:Fix_14886_checkbox/radiobutton_focus_rectangle

Conversation

@LeafShi1

@LeafShi1 LeafShi1 commented Aug 27, 2026

Copy link
Copy Markdown
Member

Fixes #14886

Root Cause

When CheckBox or RadioButton used Appearance.ToggleSwitch with VisualStylesMode.Net11, the toggle switch renderer reused ControlPaint.DrawFocusRectangle against the full ClientRectangle. That produced the legacy dotted focus rectangle across the entire control .

The renderer also did not reserve layout space for the focus indicator, so adding focus chrome at paint time could visually crowd or clip the control edges.

Proposed changes

The change updates AnimatedToggleSwitchRenderer.cs to:

  • Add focus border thickness and focus margin to ToggleSwitchMetrics.
  • Reserve the focus margin in ToggleSwitch content bounds and preferred-size calculations.
  • Draw a rounded solid focus border using the modern visual styles focus color.
  • Inset the focus border enough to avoid clipping at the control edges.
  • Reuse the same metrics snapshot for layout and painting.

Customer Impact

  • Users get a cleaner and more consistent focus style for ToggleSwitch CheckBox and RadioButton. Keyboard focus is easier to see, and the UI no longer shows the old dotted full-control outline.

Regression?

  • No

Risk

  • Minimal

Screenshots

Before

When a ToggleSwitch CheckBox or RadioButton got focus, a dotted line appeared around the entire control.

Image

After

When focused, ToggleSwitch now shows a rounded solid focus border. The border follows the system accent color, has enough reserved space.

image

Test methodology

  • Manually and unit test

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 27, 2026 09:32
@LeafShi1
LeafShi1 requested a lite review from Copilot and removed request for a team August 27, 2026 09:33

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 pull request updates the modern ToggleSwitch rendering path for CheckBox and RadioButton (when Appearance.ToggleSwitch + VisualStylesMode.Net11) to replace the legacy dotted full-control focus rectangle with a rounded, solid focus border and to reserve layout space for that focus chrome.

Changes:

  • Adds focus-border thickness and focus margin to ToggleSwitchMetrics, and uses those metrics consistently for layout and painting.
  • Replaces ControlPaint.DrawFocusRectangle with a rounded-path focus border using the modern visual-styles focus color.
  • Adds a unit test validating focus-margin reservation and basic focus-border rendering behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/System.Windows.Forms/System/Windows/Forms/Rendering/CheckBox/AnimatedToggleSwitchRenderer.cs Introduces focus metrics, reserves focus margin in layout/preferred-size, and draws a rounded focus border using the accent/high-contrast focus color.
src/test/unit/System.Windows.Forms/System/Windows/Forms/CheckBoxTests.cs Adds a focused ToggleSwitch rendering test and a small bitmap helper for validating focus-border pixels.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

…mall

CheckBox and RadioButton ToggleSwitch controls can still show keyboard
focus even when there is not enough room to paint the switch or text.
@KlausLoeffelmann

Copy link
Copy Markdown
Member

Looks good!

That said, I'm considering bundling all the render fixes in a dedicated integration branch and then conduct a few tests with all the improvements put together.

@LeafShi1

Copy link
Copy Markdown
Member Author

Looks good!

That said, I'm considering bundling all the render fixes in a dedicated integration branch and then conduct a few tests with all the improvements put together.

Sounds good. I'm happy to help validate the integration branch once the rendering fixes are combined.

@LeafShi1 LeafShi1 added waiting-review This item is waiting on review by one or more members of team and removed waiting-review This item is waiting on review by one or more members of team labels Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The dot line appeared entire control for the checkbox/radiobutton when setting the Appearance as ToggleSwitch in Net11

3 participants