-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix CheckBox/RadioButton Appearance switching in Dark Mode #14194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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 |
src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/RadioButton.cs
Outdated
Show resolved
Hide resolved
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
…/RadioButton.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
KlausLoeffelmann
left a comment
There was a problem hiding this 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!
|
/backport to release/10.0 |
|
Started backporting to |
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:
OwnerDrawproperty returns different values based on the Appearance settingAppearance = ButtonwithFlatStyle.Standardin Dark Mode,OwnerDrawbecomes false (system-drawn)Appearance = Normal,OwnerDrawis always true (custom-drawn)UpdateOwnerDraw()to handle this state transitionUpdateOwnerDraw(), the control styles (ControlStyles.UserPaint, ControlStyles.UserMouse) were not updated, and the window handle was not recreatedProposed changes
UpdateOwnerDraw()call in the Appearance setter for both CheckBox and RadioButtonHandle state change first (may RecreateHandle) and then refresh if handle wasn't recreated
Customer Impact
Regression?
Risk
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
Test environment(s)
Microsoft Reviewers: Open in CodeFlow