Fix CheckBox/RadioButton Appearance.Button + FlatStyle.Standard invisible in dark mode#14397
Open
ricardobossan wants to merge 1 commit intodotnet:mainfrom
Conversation
…ible in dark mode Fixes dotnet#14347 `CheckBox` and `RadioButton` with `Appearance.Button + FlatStyle.Standard` intentionally disabled owner-draw in dark mode to work around a VisualStyleRenderer HighDPI issue: ```csharp private protected override bool OwnerDraw => (!Application.IsDarkModeEnabled || Appearance != Appearance.Button || FlatStyle != FlatStyle.Standard) && base.OwnerDraw; ``` With `OwnerDraw = false`, WinForms delegates painting to the native ComCtl32 button (`BS_3STATE | BS_PUSHLIKE`). The native control renders with light-mode colors (or transparent) on a dark form background, making the controls completely invisible. - **`CheckBox.cs` / `RadioButton.cs`**: Remove the dark mode exception from `OwnerDraw`. Both controls now return `base.OwnerDraw` (i.e., `FlatStyle != FlatStyle.System`) unconditionally, restoring owner-draw for `Appearance.Button + FlatStyle.Standard` in dark mode. - **`CheckBoxStandardAdapter.cs` / `RadioButtonStandardAdapter.cs`**: Change `CreateButtonAdapter()` from `new ButtonStandardAdapter(Control)` to `DarkModeAdapterFactory.CreateStandardAdapter(Control)`. In dark mode this returns `ButtonDarkModeAdapter`, which renders using explicit dark mode colors (`#333333` background, `#9B9B9B` border, `#F0F0F0` text) and does not use VisualStyleRenderers, resolving both the visibility issue and the HighDPI concern that motivated the original workaround. `CheckBox` and `RadioButton` controls with `Appearance.Button + FlatStyle.Standard` are now visible and correctly styled in dark mode. Previously they were completely invisible. No. Minimal. Manual. - 11.0.100-preview.3.26161.119
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes dark-mode invisibility for CheckBox/RadioButton when using Appearance.Button + FlatStyle.Standard by restoring owner-draw in dark mode and routing “button-like” rendering through a dark-mode-capable adapter.
Changes:
- Remove dark-mode special-casing from
OwnerDrawinCheckBoxandRadioButton(now alwaysbase.OwnerDraw). - Use
DarkModeAdapterFactory.CreateStandardAdapter(...)for theAppearance.Buttonrendering path in the Standard adapters.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/RadioButton.cs | Restores owner-draw in dark mode by removing the special OwnerDraw condition. |
| src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/CheckBox.cs | Restores owner-draw in dark mode by removing the special OwnerDraw condition. |
| src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/ButtonInternal/RadioButtonStandardAdapter.cs | Routes Appearance.Button painting through the dark-mode adapter factory. |
| src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/ButtonInternal/CheckBoxStandardAdapter.cs | Routes Appearance.Button painting and sizing through the dark-mode adapter factory. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+176
to
177
| private protected override bool OwnerDraw => base.OwnerDraw; | ||
|
|
Comment on lines
109
to
111
|
|
||
| protected override ButtonBaseAdapter CreateButtonAdapter() => new ButtonStandardAdapter(Control); | ||
| protected override ButtonBaseAdapter CreateButtonAdapter() => DarkModeAdapterFactory.CreateStandardAdapter(Control); | ||
|
|
Comment on lines
+53
to
56
| private new ButtonBaseAdapter ButtonAdapter => base.ButtonAdapter; | ||
|
|
||
| protected override ButtonBaseAdapter CreateButtonAdapter() => new ButtonStandardAdapter(Control); | ||
| protected override ButtonBaseAdapter CreateButtonAdapter() => DarkModeAdapterFactory.CreateStandardAdapter(Control); | ||
|
|
| || Appearance != Appearance.Button | ||
| || FlatStyle != FlatStyle.Standard) | ||
| && base.OwnerDraw; | ||
| private protected override bool OwnerDraw => base.OwnerDraw; |
Member
|
Should we enable OwnerDraw in Standard mode? @KlausLoeffelmann |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #14347
Root Cause
CheckBoxandRadioButtonwithAppearance.Button + FlatStyle.Standardintentionally disabled owner-draw in dark mode to work around a VisualStyleRenderer HighDPI issue:With
OwnerDraw = false, WinForms delegates painting to the native ComCtl32 button (BS_3STATE | BS_PUSHLIKE). The native control renders with light-mode colors (or transparent) on a dark form background, making the controls completely invisible.Proposed changes
CheckBox.cs/RadioButton.cs: Remove the dark mode exception fromOwnerDraw. Both controls now returnbase.OwnerDraw(i.e.,FlatStyle != FlatStyle.System) unconditionally, restoring owner-draw forAppearance.Button + FlatStyle.Standardin dark mode.CheckBoxStandardAdapter.cs/RadioButtonStandardAdapter.cs: ChangeCreateButtonAdapter()fromnew ButtonStandardAdapter(Control)toDarkModeAdapterFactory.CreateStandardAdapter(Control). In dark mode this returnsButtonDarkModeAdapter, which renders using explicit dark mode colors (#333333background,#9B9B9Bborder,#F0F0F0text) and does not use VisualStyleRenderers, resolving both the visibility issue and the HighDPI concern that motivated the original workaround.Customer Impact
CheckBoxandRadioButtoncontrols withAppearance.Button + FlatStyle.Standardare now visible and correctly styled in dark mode. Previously they were completely invisible.Regression?
No.
Risk
Minimal.
Screenshots
Before
After
Test methodology
Manual.
Test environment(s)
Microsoft Reviewers: Open in CodeFlow