Skip to content

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
dotnet:mainfrom
SimonZhao888:Fix_Issue_14808
Open

Fix issue 14808: CheckBox/RadioButton: ToggleSwitch overlaps text when RightToLeft is enabled and AutoSize is false#14815
SimonZhao888 wants to merge 4 commits into
dotnet:mainfrom
SimonZhao888:Fix_Issue_14808

Conversation

@SimonZhao888

@SimonZhao888 SimonZhao888 commented Jul 27, 2026

Copy link
Copy Markdown
Member

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

  • Compute a dedicated textBounds for ToggleSwitch text by subtracting switch glyph width (plus text gap) from the control content bounds.
  • Render text using rectangle-based TextRenderer.DrawText(..., textBounds, flags) instead of point-based drawing.
  • Keep switch and text in separate layout regions to guarantee no overlap.
  • Reuse CheckBox/RadioButton default text format flags (CreateTextFormatFlags) so ToggleSwitch text wrapping/clipping behavior aligns with Normal mode.
  • Add/keep regression tests for long text + RTL + AutoSize=false to ensure text does not overlap the toggle glyph.

Customer Impact

Improves text rendering reliability for ToggleSwitch-style CheckBox/RadioButton, especially with long text and constrained widths (AutoSize=false).

  • Prevents text from overlapping the toggle glyph.
  • Aligns ToggleSwitch text wrapping/clipping behavior with Normal mode for more predictable UI results.
  • Improves RTL and long-text layout consistency without changing public APIs.

Regression?

  • No

Risk

  • Mini

Screenshots

Before

image

After

14808-1mp4.mp4

Test methodology

  • Manually

Test environment(s)

  • 11.0.100-preview.5.26302.115
Microsoft Reviewers: Open in CodeFlow

…n RightToLeft is enabled and AutoSize is false
@KlausLoeffelmann

Copy link
Copy Markdown
Member

In the screenshot, the toggle-slider-button us a but "cut" on the right side.
Do you want to extend that threshold a bit to the right?

image

Could you also be checking, how it looks when we are positioning it on the other side, and on top, bottom, and when we are using RTL?

@SimonZhao888

SimonZhao888 commented Jul 28, 2026

Copy link
Copy Markdown
Member Author

Could you also be checking, how it looks when we are positioning it on the other side, and on top, bottom, and when we are using RTL?

Done; we have extended the threshold by 2px to the right.
image

@SimonZhao888

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

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 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 textBounds region that excludes the toggle glyph area and render text via TextRenderer.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.

Comment thread src/test/unit/System.Windows.Forms/System/Windows/Forms/CheckBoxTests.cs Outdated
@SimonZhao888

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

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.

CheckBox/RadioButton: ToggleSwitch overlaps text when RightToLeft is enabled and AutoSize is false

3 participants