Skip to content

Conversation

@LeafShi1
Copy link
Member

@LeafShi1 LeafShi1 commented Jan 8, 2026

Fixes #14191

Root Cause

When switching the Appearance property between Normal and Button via PropertyGrid in Dark Mode, the CheckBox/RadioButton controls failed to update their visual state correctly.

The issue occurred because:

  1. In Dark Mode, the OwnerDraw property returns different values based on the Appearance setting
  2. When Appearance = Button with FlatStyle.Standard in Dark Mode, OwnerDraw becomes false (system-drawn)
  3. When Appearance = Normal, OwnerDraw is always true (custom-drawn)
  4. The Appearance setter was not calling UpdateOwnerDraw() to handle this state transition
  5. Without calling UpdateOwnerDraw(), the control styles (ControlStyles.UserPaint, ControlStyles.UserMouse) were not updated, and the window handle was not recreated

Proposed changes

  • Added UpdateOwnerDraw() call in the Appearance setter for both CheckBox and RadioButton
  • Optimized call order to avoid unnecessary operations:
    Handle state change first (may RecreateHandle) and then refresh if handle wasn't recreated

Customer Impact

  • CheckBox and RadioButton now correctly switch between Normal and Button appearance in Dark Mode

Regression?

  • Yes

Risk

  • Minimal

Screenshots

Before

The CheckBox/RadioButton cannot back to normal status when switching the Appearance property in propertyGrid

BeforeChanges.mp4

After

CheckBox / RadioButton correctly switch between Normal and Button appearance in Dark Mode

AfterChanges.mp4

Test methodology

  • Manually

Test environment(s)

  • .net 11.0.0-alpha.1.26055.114
Microsoft Reviewers: Open in CodeFlow

@LeafShi1 LeafShi1 requested a review from a team as a code owner January 8, 2026 03:18
@github-actions github-actions bot added the area-DarkMode Issues relating to Dark Mode feature label Jan 8, 2026
Copy link
Contributor

Copilot AI left a comment

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 fixes a visual update bug in CheckBox and RadioButton controls when switching between Normal and Button appearance in Dark Mode. The root cause was that UpdateOwnerDraw() was called too late (only in the else branch), preventing proper control style synchronization and handle recreation when needed.

Key Changes:

  • Moved UpdateOwnerDraw() call to execute before the if/else branching logic in both CheckBox and RadioButton
  • Removed the previous UpdateOwnerDraw() call from the else branch
  • Updated inline comments to accurately reflect the new execution order and behavior

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/CheckBox.cs Repositioned UpdateOwnerDraw() call to occur before if/else logic, ensuring OwnerDraw state is updated before branching decisions are made
src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/RadioButton.cs Applied identical fix as CheckBox - moved UpdateOwnerDraw() before if/else logic for proper Dark Mode appearance switching

@codecov
Copy link

codecov bot commented Jan 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.15319%. Comparing base (15506ad) to head (a4d7b5b).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@                 Coverage Diff                 @@
##                main      #14194         +/-   ##
===================================================
+ Coverage   77.15242%   77.15319%   +0.00076%     
===================================================
  Files           3279        3279                 
  Lines         645333      645333                 
  Branches       47720       47720                 
===================================================
+ Hits          497890      497895          +5     
+ Misses        143757      143741         -16     
- Partials        3686        3697         +11     
Flag Coverage Δ
Debug 77.15319% <100.00000%> (+0.00076%) ⬆️
integration 18.98737% <0.00000%> (+0.00312%) ⬆️
production 52.01720% <100.00000%> (+0.00174%) ⬆️
test 97.40559% <ø> (ø)
unit 49.46431% <100.00000%> (+0.02256%) ⬆️

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.

…/RadioButton.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Member

@KlausLoeffelmann KlausLoeffelmann left a comment

Choose a reason for hiding this comment

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

Perfect, we were on the right track here! :-)

Thanks for fixing this!

@LeafShi1 LeafShi1 merged commit af998d1 into dotnet:main Jan 14, 2026
8 checks passed
@LeafShi1
Copy link
Member Author

/backport to release/10.0

@github-actions
Copy link
Contributor

Started backporting to release/10.0 (link to workflow run)

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

Labels

area-DarkMode Issues relating to Dark Mode feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Dark Mode] The CheckBox/RadioButton cannot back to normal status when switching the Appearance property in propertyGrid

4 participants