Skip to content

Fix RadioButton focus rectangle visibility when an image is assigned - #15299

Merged
LeafShi1 merged 1 commit into
dotnet:mainfrom
LeafShi1:Fix_15289_RadioButton_Focus_issue
Oct 23, 2026
Merged

LeafShi1 merged 1 commit into
dotnet:mainfrom
LeafShi1:Fix_15289_RadioButton_Focus_issue

Conversation

@LeafShi1

@LeafShi1 LeafShi1 commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Fixes #15289

Root cause

The shared button layout calculates the focus rectangle from the union of the text and image bounds. When AutoSize is false and the image is larger than the available space, the focus rectangle can extend outside the visible control area, making the dotted focus indicator invisible.

Proposed change

  • Set the focus rectangle to TextBounds when a RadioButton has both text and an image, so the focus indicator surrounds only the text.

Customer Impact

  • Keyboard users can see which RadioButton has focus when a large image is assigned and AutoSize is false.
  • RadioButtons with text and an image now draw the focus indicator around the text rather than including the image, consistent with the standard CheckBox's text-focused behavior.

Regression?

  • No. The issue also reproduces on .NET Framework.

Risk

  • Minimal

Screenshots

Before

image

After

image

Test methodology

  • Unit test and manual tests

Test environment(s)

  • .net 12.0.0-beta.26519.114
Microsoft Reviewers: Open in CodeFlow

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.

🟢 Approval recommended

The localized change preserves existing fallback behavior, includes targeted regression coverage, and has no unresolved findings.

No open issues 🎉

What changed in this PR

Fixes #15289 by keeping the RadioButton keyboard-focus indicator around the text when an image is assigned, preventing oversized images from pushing the indicator outside the visible control.

Changes:

  • Uses text bounds for the focus rectangle when both text and an image are present.
  • Preserves existing behavior for textless controls and adds geometry and bitmap regression tests across Standard, Flat, and Popup styles.
File Description
src/​test/​unit/​System.Windows.Forms/​System/​Windows/​Forms/​RadioButtonBaseAdapterTests.cs Adds focus simulation and regression coverage for image sizes, AutoSize, and rendering styles.
src/​System.Windows.Forms/​System/​Windows/​Forms/​Controls/​Buttons/​ButtonInternal/​RadioButtonBaseAdapter.cs Restricts the focus rectangle to text bounds when text and an image are present.

Review effort: Balanced

@codecov

codecov Bot commented Oct 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 37.84861%. Comparing base (aba5097) to head (d3aeec9).

Additional details and impacted files
@@              Coverage Diff              @@
##                main      #15299   +/-   ##
=============================================
  Coverage   37.84861%   37.84861%           
=============================================
  Files            246         246           
  Lines           9789        9789           
  Branches        1031        1031           
=============================================
  Hits            3705        3705           
  Misses          5920        5920           
  Partials         164         164           
Flag Coverage Δ
Debug 37.84861% <ø> (ø)
production 40.04608% <ø> (ø)
test 20.64923% <ø> (ø)
unit 40.04608% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@LeafShi1
LeafShi1 merged commit c37f09d into dotnet:main Oct 23, 2026
10 checks passed
@LeafShi1
LeafShi1 deleted the Fix_15289_RadioButton_Focus_issue branch October 23, 2026 01:15
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 27, 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.

There is no dotline for the RadioButton control after setting the Image property

3 participants