From 98ec7f725d088227ac160a25494ebf0ba8ae2463 Mon Sep 17 00:00:00 2001 From: "Ricardo Bossan (BEYONDSOFT CONSULTING INC) (from Dev Box)" Date: Fri, 20 Feb 2026 20:03:03 -0300 Subject: [PATCH 1/4] Fixes #11933 `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 --- .../Controls/ToolStrips/ToolStripRenderer.cs | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/ToolStripRenderer.cs b/src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/ToolStripRenderer.cs index 5ce502caaaf..cf2689a9cfe 100644 --- a/src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/ToolStripRenderer.cs +++ b/src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/ToolStripRenderer.cs @@ -863,14 +863,22 @@ protected virtual void OnRenderItemCheck(ToolStripItemImageRenderEventArgs e) image = CreateDisabledImage(image, e.ImageAttributes); } - if (SystemInformation.HighContrast && image is Bitmap bitmap) + if (image is Bitmap bitmap) { - Color backgroundColor = e.Item.Selected ? SystemColors.Highlight : e.Item.BackColor; - - if (ControlPaint.IsDark(backgroundColor)) + if (Application.IsDarkModeEnabled) + { + // In dark mode, the check mark icons are dark glyphs designed for light + // backgrounds. Invert the foreground color so they are visible on dark backgrounds. + image = ControlPaint.CreateBitmapWithInvertedForeColor(bitmap, e.Item.BackColor); + } + else if (SystemInformation.HighContrast) { - Image invertedImage = ControlPaint.CreateBitmapWithInvertedForeColor(bitmap, e.Item.BackColor); - image = invertedImage; + Color backgroundColor = e.Item.Selected ? SystemColors.Highlight : e.Item.BackColor; + + if (ControlPaint.IsDark(backgroundColor)) + { + image = ControlPaint.CreateBitmapWithInvertedForeColor(bitmap, e.Item.BackColor); + } } } } From 312455d01e346bb92720c585aed437a39726dc4d Mon Sep 17 00:00:00 2001 From: "Ricardo Bossan (BEYONDSOFT CONSULTING INC) (from Dev Box)" Date: Tue, 24 Feb 2026 21:25:50 -0300 Subject: [PATCH 2/4] Addresses feedback --- .../Forms/Controls/ToolStrips/ToolStripRenderer.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/ToolStripRenderer.cs b/src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/ToolStripRenderer.cs index cf2689a9cfe..370f9b1157d 100644 --- a/src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/ToolStripRenderer.cs +++ b/src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/ToolStripRenderer.cs @@ -865,13 +865,7 @@ protected virtual void OnRenderItemCheck(ToolStripItemImageRenderEventArgs e) if (image is Bitmap bitmap) { - if (Application.IsDarkModeEnabled) - { - // In dark mode, the check mark icons are dark glyphs designed for light - // backgrounds. Invert the foreground color so they are visible on dark backgrounds. - image = ControlPaint.CreateBitmapWithInvertedForeColor(bitmap, e.Item.BackColor); - } - else if (SystemInformation.HighContrast) + if (SystemInformation.HighContrast) { Color backgroundColor = e.Item.Selected ? SystemColors.Highlight : e.Item.BackColor; @@ -880,6 +874,12 @@ protected virtual void OnRenderItemCheck(ToolStripItemImageRenderEventArgs e) image = ControlPaint.CreateBitmapWithInvertedForeColor(bitmap, e.Item.BackColor); } } + else if (Application.IsDarkModeEnabled) + { + // In dark mode, the check mark icons are dark glyphs designed for light + // backgrounds. Invert the foreground color so they are visible on dark backgrounds. + image = ControlPaint.CreateBitmapWithInvertedForeColor(bitmap, e.Item.BackColor); + } } } From b09d495c258b5ee9b62e39c1d46cde1114d22b65 Mon Sep 17 00:00:00 2001 From: "Ricardo Bossan (BEYONDSOFT CONSULTING INC) (from Dev Box)" Date: Thu, 26 Feb 2026 00:00:14 -0300 Subject: [PATCH 3/4] Handles feedback --- .../Controls/ToolStrips/ToolStripRenderer.cs | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/ToolStripRenderer.cs b/src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/ToolStripRenderer.cs index 370f9b1157d..e4b981db9a7 100644 --- a/src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/ToolStripRenderer.cs +++ b/src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/ToolStripRenderer.cs @@ -856,11 +856,16 @@ protected virtual void OnRenderItemCheck(ToolStripItemImageRenderEventArgs e) return; } + // Track images we allocate so they can be disposed after drawing. + Image? disabledImage = null; + Image? invertedImage = null; + if (e.Item is not null) { if (!e.Item.Enabled) { - image = CreateDisabledImage(image, e.ImageAttributes); + disabledImage = CreateDisabledImage(image, e.ImageAttributes); + image = disabledImage; } if (image is Bitmap bitmap) @@ -871,20 +876,30 @@ protected virtual void OnRenderItemCheck(ToolStripItemImageRenderEventArgs e) if (ControlPaint.IsDark(backgroundColor)) { - image = ControlPaint.CreateBitmapWithInvertedForeColor(bitmap, e.Item.BackColor); + invertedImage = ControlPaint.CreateBitmapWithInvertedForeColor(bitmap, e.Item.BackColor); + image = invertedImage; } } else if (Application.IsDarkModeEnabled) { - // In dark mode, the check mark icons are dark glyphs designed for light - // backgrounds. Invert the foreground color so they are visible on dark backgrounds. - image = ControlPaint.CreateBitmapWithInvertedForeColor(bitmap, e.Item.BackColor); + Color backgroundColor = e.Item.Selected ? SystemColors.Highlight : e.Item.BackColor; + + if (ControlPaint.IsDark(backgroundColor)) + { + // In dark mode, the check mark icons are dark glyphs designed for light + // backgrounds. Invert the foreground color so they are visible on dark backgrounds. + invertedImage = ControlPaint.CreateBitmapWithInvertedForeColor(bitmap, e.Item.BackColor); + image = invertedImage; + } } } } e.Graphics.DrawImage(image, imageRect, 0, 0, imageRect.Width, imageRect.Height, GraphicsUnit.Pixel, e.ImageAttributes); + + disabledImage?.Dispose(); + invertedImage?.Dispose(); } /// From 77ba59d05248b7ced86bb707060517d97055536a Mon Sep 17 00:00:00 2001 From: "Ricardo Bossan (BEYONDSOFT CONSULTING INC) (from Dev Box)" Date: Tue, 3 Mar 2026 20:04:48 -0300 Subject: [PATCH 4/4] Handles feedback --- .../Windows/Forms/Controls/ToolStrips/ToolStripRenderer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/ToolStripRenderer.cs b/src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/ToolStripRenderer.cs index e4b981db9a7..b62c48db870 100644 --- a/src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/ToolStripRenderer.cs +++ b/src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/ToolStripRenderer.cs @@ -876,7 +876,7 @@ protected virtual void OnRenderItemCheck(ToolStripItemImageRenderEventArgs e) if (ControlPaint.IsDark(backgroundColor)) { - invertedImage = ControlPaint.CreateBitmapWithInvertedForeColor(bitmap, e.Item.BackColor); + invertedImage = ControlPaint.CreateBitmapWithInvertedForeColor(bitmap, backgroundColor); image = invertedImage; } } @@ -888,7 +888,7 @@ protected virtual void OnRenderItemCheck(ToolStripItemImageRenderEventArgs e) { // In dark mode, the check mark icons are dark glyphs designed for light // backgrounds. Invert the foreground color so they are visible on dark backgrounds. - invertedImage = ControlPaint.CreateBitmapWithInvertedForeColor(bitmap, e.Item.BackColor); + invertedImage = ControlPaint.CreateBitmapWithInvertedForeColor(bitmap, backgroundColor); image = invertedImage; } }