Fix issue 14808: CheckBox/RadioButton: ToggleSwitch overlaps text when RightToLeft is enabled and AutoSize is false - #14815
Open
SimonZhao888 wants to merge 4 commits into
Open
Conversation
…n RightToLeft is enabled and AutoSize is false
Member
Member
Author
Member
Author
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
SimonZhao888
requested review from
KlausLoeffelmann,
LeafShi1,
Copilot and
ricardobossan
July 28, 2026 07:47
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses WinForms ToggleSwitch-style CheckBox/RadioButton text layout issues under RTL + constrained width by introducing explicit text layout bounds and switching ToggleSwitch text rendering to rectangle-based TextRenderer.DrawText.
Changes:
- Compute a dedicated
textBoundsregion that excludes the toggle glyph area and render text viaTextRenderer.DrawText(..., Rectangle, ..., flags). - Adjust toggle switch horizontal placement logic to account for an inset derived from border thickness.
- Update an existing unit test assertion to allow small edge tolerance when validating switch positioning.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/System.Windows.Forms/System/Windows/Forms/Rendering/CheckBox/AnimatedToggleSwitchRenderer.cs |
Adds text-bounds computation + rectangle-based text rendering with CreateTextFormatFlags, and tweaks switch X positioning. |
src/test/unit/System.Windows.Forms/System/Windows/Forms/CheckBoxTests.cs |
Loosens edge-position assertions for the toggle glyph to account for the new inset behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Member
Author
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
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 #14808
Root Cause
In ToggleSwitch mode, text rendering was position-based (DrawText with a point) rather than bounds-based.
When text was longer than available width, there was no hard text layout rectangle excluding the switch glyph area, so text could overlap the toggle or be clipped inconsistently (including mid-word truncation behavior different from Normal mode).
Proposed changes
Customer Impact
Improves text rendering reliability for ToggleSwitch-style CheckBox/RadioButton, especially with long text and constrained widths (AutoSize=false).
Regression?
Risk
Screenshots
Before
After
14808-1mp4.mp4
Test methodology
Test environment(s)
Microsoft Reviewers: Open in CodeFlow