Skip to content

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

Open
SimonZhao888 wants to merge 3 commits into
dotnet:mainfrom
SimonZhao888:Fix_Issue_14859
Open

Fix issue 14859: CheckBox and RadioButton ignore explicit BackColor values in VisualStylesMode.Net11#14865
SimonZhao888 wants to merge 3 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 1.1 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,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

draft draft PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CheckBox and RadioButton ignore explicit BackColor values in VisualStylesMode.Net11

2 participants