Skip to content

Fix issue 14859: CheckBox and RadioButton ignore explicit BackColor values in VisualStylesMode.Net11 - #14865

Merged
SimonZhao888 merged 4 commits into
dotnet:mainfrom
SimonZhao888:Fix_Issue_14859
Sep 4, 2026
Merged

SimonZhao888 merged 4 commits into
dotnet:mainfrom
SimonZhao888:Fix_Issue_14859

Conversation

@SimonZhao888

@SimonZhao888 SimonZhao888 commented Aug 7, 2026 •

Copy link
Copy Markdown
Member

Fixes #14859

Root Cause

The NET11 Visual Styles rendering path overrides the BackColor explicitly set by the user, causing CheckBox and RadioButton controls to deviate from the standard WinForms property precedence rules.

Proposed changes

  • Retain the default appearance of .NET 11 visual styles, but if the developer explicitly sets the BackColor, render using the developer-specified value.
  • Add test cases for CheckBox and RadioButton.

Customer Impact

Restore existing WinForms behavior, namely, when the user sets the BackColor for CheckBox and RadioButton, the controls will be drawn with reference to the set value.

Regression?

  • No

Risk

  • Mini

Screenshots

Before

image

After

DarkMode:

14865-DarkMode.mp4

Light:

14865-Light.mp4

Test methodology

  • Manually
  • Automated test cases

Test environment(s)

  • 11.0.0-preview.7.26381.103

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 fixes a rendering regression in the .NET 11 modern rendering path (VisualStylesMode.Net11) where CheckBox and RadioButton ignored explicitly set BackColor values by always painting the parent background.

Changes:

  • Updated CheckBoxModernAdapter and RadioButtonModernAdapter to fill the control background with BackColor when UseVisualStyleBackColor == false and BackColor is fully opaque.
  • Kept ParentBackgroundRenderer.Paint(...) for visual-style-backed and transparent/alpha backgrounds to preserve parent blending behavior.
  • Added regression tests for both controls to validate explicit BackColor behavior in VisualStylesMode.Net11, and adjusted existing accent tests to avoid being affected by the new background fill.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/ButtonInternal/CheckBoxModernAdapter.cs Conditionally fills with explicit BackColor when visual style background is disabled and color is opaque.
src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/ButtonInternal/RadioButtonModernAdapter.cs Same conditional background fill logic for RadioButton in modern Net11 mode.
src/test/unit/System.Windows.Forms/System/Windows/Forms/CheckBoxTests.cs Adds regression test for explicit BackColor in Net11; updates accent test to set UseVisualStyleBackColor = true.
src/test/unit/System.Windows.Forms/System/Windows/Forms/RadioButtonTests.cs Adds regression test for explicit BackColor in Net11; updates accent test to set UseVisualStyleBackColor = true.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@SimonZhao888
SimonZhao888 marked this pull request as draft August 7, 2026 06:59
@dotnet-policy-service dotnet-policy-service Bot added the draft draft PR label Aug 8, 2026
@SimonZhao888
SimonZhao888 marked this pull request as ready for review August 10, 2026 06:53
@SimonZhao888
SimonZhao888 requested a lite review from Copilot August 10, 2026 06:53

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

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Suppressed comments (2)

src/test/unit/System.Windows.Forms/System/Windows/Forms/RadioButtonTests.cs:224

  • This test sets BackColor = Color.Red and then counts pixels matching Application.SystemVisualSettings.AccentColor across the whole bitmap. If the system accent color is red (or close enough for the 24-channel tolerance), the solid background will be counted as an accent pixel, making the unchecked case flaky. Consider using a BackColor derived from (and guaranteed to differ from) the accent color, and use that value for the background assertion.
        using RadioButton control = new()
        {
            BackColor = Color.Red,
            UseVisualStyleBackColor = true,
            Checked = isChecked,

src/test/unit/System.Windows.Forms/System/Windows/Forms/CheckBoxTests.cs:586

  • The test uses BackColor = Color.Red and then searches the whole bitmap for Application.SystemVisualSettings.AccentColor. If the Windows accent color happens to match red, the background fill will be counted as an accent pixel and can make the expectedAccent assertion flaky (especially for the unchecked case). Use a BackColor derived from (and guaranteed to differ from) the accent color, and reuse that value in the background assertion.
        using CheckBox box = new()
        {
            BackColor = Color.Red,
            UseVisualStyleBackColor = true,
            CheckState = checkState,

@dotnet-policy-service dotnet-policy-service Bot removed the draft draft PR label Aug 10, 2026
@KlausLoeffelmann

Copy link
Copy Markdown
Member

This looks good.
Couple of questions, though:

  • In the last screen video, at around 18 seconds, the background color of the switch itself changes from red to blau-ish. Is that because you changed the accent color?
  • Could you set for one checkbox and one RadioButton the Margin to 15 and also the Padding to 15, and then set individual backcolors? I just want to see, what controls the size of the background effectively. Thanks!

(Other than that, I would approve. I just want to see, if we would need to change something else based on the Padding/Margin outcome.)

@SimonZhao888

Copy link
Copy Markdown
Member Author
  • In the last screen video, at around 18 seconds, the background color of the switch itself changes from red to blau-ish. Is that because you changed the accent color?

Yes. I intentionally changed the AccentColor at that point to test the functionality. The switch background updates from red to a bluish color because it's picking up the new accent color as expected.

  • Could you set for one checkbox and one RadioButton the Margin to 15 and also the Padding to 15, and then set individual backcolors? I just want to see, what controls the size of the background effectively. Thanks!

Sure. I set both a CheckBox and a RadioButton with Margin = 15 and Padding = 15, and assigned individual BackColor values. The attached screenshot shows the result.

From what I can see, neither Margin nor Padding affects the size of the painted background area. The background is still rendered within the control's bounds. Margin only affects the spacing around the control during layout, while Padding affects the content layout inside the control.

Based on this test, the effective background size appears to be determined primarily by the control's own size rather than its Margin or Padding settings.

Please let me know if there are any other scenarios you'd like me to try.

image

@SimonZhao888
SimonZhao888 marked this pull request as draft August 14, 2026 07:28
@SimonZhao888 SimonZhao888 added the draft draft PR label Aug 14, 2026
@SimonZhao888
SimonZhao888 marked this pull request as ready for review August 17, 2026 03:15
@SimonZhao888 SimonZhao888 removed the draft draft PR label Aug 17, 2026
@SimonZhao888 SimonZhao888 added the waiting-review This item is waiting on review by one or more members of team label Sep 3, 2026

@KlausLoeffelmann KlausLoeffelmann left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit: !

Thanks!

@KlausLoeffelmann KlausLoeffelmann removed the waiting-review This item is waiting on review by one or more members of team label Sep 4, 2026
@SimonZhao888
SimonZhao888 merged commit 91d6b29 into dotnet:main Sep 4, 2026
8 checks passed
@SimonZhao888
SimonZhao888 deleted the Fix_Issue_14859 branch September 4, 2026 01:02
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 4, 2026
KlausLoeffelmann pushed a commit that referenced this pull request Sep 12, 2026
…alues in VisualStylesMode.Net11 (#14865)

* Fix issue 14859: CheckBox and RadioButton ignore explicit BackColor values in VisualStylesMode.Net11

* Sync the latest code and apply relevant fixes.

* Handle feedback

---------

Co-authored-by: Simon Zhao (BEYONDSOFT CONSULTING INC) <[email protected]>
LeafShi1 pushed a commit that referenced this pull request Sep 15, 2026
…alues in VisualStylesMode.Net11 (#14865)

* Fix issue 14859: CheckBox and RadioButton ignore explicit BackColor values in VisualStylesMode.Net11

* Sync the latest code and apply relevant fixes.

* Handle feedback

---------

Co-authored-by: Simon Zhao (BEYONDSOFT CONSULTING INC) <[email protected]>
LeafShi1 added a commit that referenced this pull request Sep 15, 2026
…oButton (#15101)

Replays #14865 onto the corrected `integration/11.0-RC2` branch based on
`release/11.0`.
KlausLoeffelmann added a commit that referenced this pull request Sep 21, 2026
…5143)

## Description

Backport the selected .NET 11 Visual Styles fixes to release/11.0 for
RC2.

This PR consolidates the following previously reviewed fixes into a
single backport:

- #14853 - Fix editable control border color in NET11 visual styles
- #14904 - Fix modern RadioButton glyph clipping in RTL layouts
- #14910 - Fix GroupBox background image rendering in .NET 11 visual
styles
- #14865 - Fix CheckBox and RadioButton explicit BackColor handling in
VisualStylesMode.Net11
- #14860 - Fix Button focus indicator when hosted on a TabPage
- #14827 - Fix ComboBox rendering with DropDownStyle.Simple
- #15019 - Fix setting VisualStylesMode to Classic in the Properties
window
- #14887 - Fix text clipping in controls such as TextBox and ComboBox
- #14929 - Fix inherited ForeColor/BackColor updates for controls inside
GroupBox
- #14815 - Fix ToggleSwitch text overlap in RTL layouts
- #15033 - Disable NET11 VisualStylesMode for composite controls until
their layout modernization is completed
- #15113 - Reinstate per\-state Net11 editable\-control border strokes
- #15159 - Fix CheckBox and RadioButton render transparently over a
parent GroupBox BackgroundImage in VisualStylesMode.Net11
- #15163 - Add design-time analyzer guardrails and shared analyzer test
harness

## Customer Impact

- Without these fixes, applications using the .NET 11 Visual Styles may
encounter rendering, layout, color, RTL, and design\-time issues across
several WinForms controls, including TextBox, ComboBox, Button,
CheckBox, RadioButton, GroupBox, and ToggleSwitch.
The changes also prevent NET11 VisualStylesMode from being applied to
composite controls that are not yet ready for the new visual style
behavior.
- The design-time analyzer guardrails detect unsupported
Designer-generated code patterns that can break designer loading or
serialization, and provide actionable guidance without changing
application runtime behavior. Individual diagnostics remain
configurable.

## Regression

Most of the changes in this backport address regressions or incorrect
behavior identified during .NET 11 Visual Styles development and
validation.

#15113 introduces the updated per-state border styling for editable
controls as part of the .NET 11 Visual Styles. The remaining changes fix
rendering, layout, color, RTL, and design-time issues related to the new
visual styles.

#15163 does not address a shipped runtime regression. It introduces
design-time analyzer guardrails and includes fixes for analyzer false
positives, missed cases, and VB analyzer exceptions identified during
development.

The individual changes have been reviewed and validated in their
original PRs, and the selected changes were also tested before this
backport.

## Testing

Each fix includes its corresponding tests and validation from the
original PR.

The selected fixes were also tested together to validate the combined
RC2 changes before backporting them to release/11.0.

### Risk

**Medium.** - The primary risk is in WinForms control rendering and
layout under the .NET 11 Visual Styles, along with the newly added
design\-time analyzer behavior. This backport includes both visual-style
fixes and an intentional visual behavior change for editable\-control
borders introduced by #15113.

The affected areas include:

- Editable control border rendering and state-specific border styling.
- CheckBox and RadioButton colors, glyphs, and background rendering.
- RTL layout for RadioButton and ToggleSwitch.
- GroupBox background, color inheritance, and child-control rendering.
- Button focus indicator rendering.
- ComboBox layout and rendering.
- Text layout and clipping in editable controls.
- VisualStylesMode behavior at design time.
- VisualStylesMode availability for composite controls.
- Design-time analyzer diagnostics. Some diagnostics are enabled as
errors by default and can fail builds containing unsupported
Designer-generated code. The diagnostics remain individually
configurable.

The individual changes have been reviewed and validated in their
original PRs, and the combined changes were tested together before this
backport.


## Fix

Backport the selected .NET 11 Visual Styles changes for RC2, including:

- Introduce the new per-state border styling for editable controls.
- Fix editable-control border colors and text rendering.
- Fix CheckBox, RadioButton, and ToggleSwitch rendering, including RTL
scenarios.
- Fix GroupBox background rendering and inherited colors.
- Fix Button focus indicator rendering.
- Fix ComboBox layout and rendering.
- Fix VisualStylesMode configuration in the Properties window.
- Disable NET11 VisualStylesMode for composite controls that are not yet
ready for the new visual styles.
- Adds design-time analyzer guardrails and the shared analyzer test
infrastructure
@LeafShi1 LeafShi1 modified the milestones: 12.0-preview1, 11.0-rc2 Sep 22, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CheckBox and RadioButton ignore explicit BackColor values in VisualStylesMode.Net11

4 participants