Fix ToggleSwitch focus border rendering for CheckBox and RadioButton - #14990
Fix ToggleSwitch focus border rendering for CheckBox and RadioButton#14990LeafShi1 wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
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.DrawFocusRectanglewith 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.
|
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. |
Fixes #14886
Root Cause
When
CheckBoxorRadioButtonusedAppearance.ToggleSwitchwithVisualStylesMode.Net11, the toggle switch renderer reusedControlPaint.DrawFocusRectangleagainst the fullClientRectangle. 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.csto:ToggleSwitchMetrics.Customer Impact
Regression?
Risk
Screenshots
Before
When a ToggleSwitch CheckBox or RadioButton got focus, a dotted line appeared around the entire control.
After
When focused, ToggleSwitch now shows a rounded solid focus border. The border follows the system accent color, has enough reserved space.
Test methodology
Test environment(s)
Microsoft Reviewers: Open in CodeFlow