Indeterminate and checked ToolStripMenuItem icons are now clearly visible in dark mode on ContextMenuStrip, MenuStrip, StatusStrip and ToolStrip drop-down buttons.#14317
Conversation
`ToolStripRenderer.OnRenderItemCheck` only inverted the check mark glyph when `SystemInformation.HighContrast` was true. In regular dark mode the check mark icons (designed for light backgrounds) were drawn as-is, resulting in a dark glyph on a dark background. Extended the inversion logic in `ToolStripRenderer.OnRenderItemCheck` to also trigger when `Application.IsDarkModeEnabled` is true, using the existing `ControlPaint.CreateBitmapWithInvertedForeColor` helper. The high contrast path is preserved as a separate branch since it already handles its own background-color detection. Indeterminate and checked `ToolStripMenuItem` icons are now clearly visible in dark mode on `ContextMenuStrip`, `MenuStrip`, `StatusStrip` and `ToolStrip` drop-down buttons. No Minimal Manual - 11.0.100-preview.1.26078.121
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #14317 +/- ##
===================================================
+ Coverage 77.21743% 77.24331% +0.02588%
===================================================
Files 3279 3280 +1
Lines 645138 645129 -9
Branches 47730 47737 +7
===================================================
+ Hits 498159 498319 +160
+ Misses 143289 143117 -172
- Partials 3690 3693 +3
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
|
LGTM! |
src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/ToolStripRenderer.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
This PR fixes a visibility issue where checked and indeterminate ToolStripMenuItem icons were barely visible in dark mode because the dark check mark glyphs designed for light backgrounds were rendered as-is on dark backgrounds.
Changes:
- Extended the inversion logic in
ToolStripRenderer.OnRenderItemCheckto trigger for dark mode in addition to high contrast mode - Used
ControlPaint.CreateBitmapWithInvertedForeColorto invert check mark glyphs whenApplication.IsDarkModeEnabledis true
src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/ToolStripRenderer.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/ToolStripRenderer.cs
Show resolved
Hide resolved
|
Please consider Copilot's comments |
| if (ControlPaint.IsDark(backgroundColor)) | ||
| if (ControlPaint.IsDark(backgroundColor)) | ||
| { | ||
| invertedImage = ControlPaint.CreateBitmapWithInvertedForeColor(bitmap, e.Item.BackColor); |
There was a problem hiding this comment.
To maintain logical consistency, the inversion here should use the same backgroundColor parameter as the conditional statement.
Fixes #11933
Root Cause
ToolStripRenderer.OnRenderItemCheckonly inverted the check mark glyph whenSystemInformation.HighContrastwas true. In regular dark mode the check mark icons (designed for light backgrounds) were drawn as-is, resulting in a dark glyph on a dark background.Proposed changes
Extended the inversion logic in
ToolStripRenderer.OnRenderItemCheckto also trigger whenApplication.IsDarkModeEnabledis true, using the existingControlPaint.CreateBitmapWithInvertedForeColorhelper. The high contrast path is preserved as a separate branch since it already handles its own background-color detection.Customer Impact
Indeterminate and checked
ToolStripMenuItemicons are now clearly visible in dark mode onContextMenuStrip,MenuStrip,StatusStripandToolStripdrop-down buttons.Regression?
No
Risk
Minimal
Screenshots
Before
After
Test methodology
Manual
Test environment(s)
Microsoft Reviewers: Open in CodeFlow