From 5f00f95bd8aeb165f188a484cd15394f98bdfdaa Mon Sep 17 00:00:00 2001 From: "Ricardo Bossan (BEYONDSOFT CONSULTING INC) (from Dev Box)" Date: Thu, 9 Oct 2025 20:54:36 -0300 Subject: [PATCH] Fixes #13901 `ColorEditor.ColorUI` and `CursorEditor.CursorUI` use owner-draw ListBoxes with custom `OnDrawItem` handlers that use `DrawItemEventArgs.ForeColor` for text rendering. In Dark Mode, this property returns dark text color for selected items, creating poor contrast against the bright blue selection background. - Modified `ColorEditor.ColorUI.OnListDrawItem()` to use `SystemColors.ControlText` for selected item text in Dark Mode - Modified `CursorEditor.CursorUI.OnDrawItem()` to use `SystemColors.ControlText` for selected item text in Dark Mode Users can now properly read selected items in `PropertyGrid` color and cursor dropdowns when using Dark Mode. No Minimal Manual testing - 10.0.100-rc.1.25420.111 --- .../src/System/Drawing/Design/ColorEditor.ColorUI.cs | 9 ++++++++- .../src/System/Drawing/Design/CursorEditor.CursorUI.cs | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/System.Windows.Forms.Design/src/System/Drawing/Design/ColorEditor.ColorUI.cs b/src/System.Windows.Forms.Design/src/System/Drawing/Design/ColorEditor.ColorUI.cs index 4e693dc32eb..66475d0f876 100644 --- a/src/System.Windows.Forms.Design/src/System/Drawing/Design/ColorEditor.ColorUI.cs +++ b/src/System.Windows.Forms.Design/src/System/Drawing/Design/ColorEditor.ColorUI.cs @@ -274,7 +274,14 @@ private void OnListDrawItem(object? sender, DrawItemEventArgs die) _editor.PaintValue(value, graphics, new Rectangle(die.Bounds.X + 2, die.Bounds.Y + 2, 22, die.Bounds.Height - 4)); graphics.DrawRectangle(SystemPens.WindowText, new Rectangle(die.Bounds.X + 2, die.Bounds.Y + 2, 22 - 1, die.Bounds.Height - 4 - 1)); - Brush foreBrush = new SolidBrush(die.ForeColor); + + Color textColor = die.ForeColor; + if (Application.IsDarkModeEnabled && die.State.HasFlag(DrawItemState.Selected)) + { + textColor = SystemColors.ControlText; + } + + Brush foreBrush = new SolidBrush(textColor); graphics.DrawString(value.Name, font, foreBrush, die.Bounds.X + 26, die.Bounds.Y); foreBrush.Dispose(); } diff --git a/src/System.Windows.Forms.Design/src/System/Drawing/Design/CursorEditor.CursorUI.cs b/src/System.Windows.Forms.Design/src/System/Drawing/Design/CursorEditor.CursorUI.cs index 94a4b69e153..4394ae47363 100644 --- a/src/System.Windows.Forms.Design/src/System/Drawing/Design/CursorEditor.CursorUI.cs +++ b/src/System.Windows.Forms.Design/src/System/Drawing/Design/CursorEditor.CursorUI.cs @@ -64,7 +64,14 @@ protected override void OnDrawItem(DrawItemEventArgs e) Cursor cursor = (Cursor)Items[e.Index]; string? text = _cursorConverter.ConvertToString(cursor); Font font = e.Font!; - using var brushText = e.ForeColor.GetCachedSolidBrushScope(); + + Color textColor = e.ForeColor; + if (Application.IsDarkModeEnabled && e.State.HasFlag(DrawItemState.Selected)) + { + textColor = SystemColors.ControlText; + } + + using var brushText = textColor.GetCachedSolidBrushScope(); var cursorWidth = ScaleHelper.ScaleSmallIconToDpi(Icon.FromHandle(cursor.Handle), DeviceDpi).Size.Width; e.DrawBackground();