From 8525291c8ffd23dde66e5186c1b9ec07034ffea8 Mon Sep 17 00:00:00 2001 From: Leaf Shi Date: Thu, 28 Aug 2025 02:40:28 -0700 Subject: [PATCH] Scale the Cursor editor according to DPI --- .../System/Drawing/Design/CursorEditor.CursorUI.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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 aaf6d3c5b1b..94a4b69e153 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 @@ -19,7 +19,8 @@ private class CursorUI : ListBox public CursorUI() { - Height = 310; + Height = ScaleHelper.IsScalingRequired ? ScaleHelper.ScaleToInitialSystemDpi(310) : 310; + ItemHeight = Math.Max(4 + Cursors.Default.Size.Height, Font.Height); DrawMode = DrawMode.OwnerDrawFixed; BorderStyle = BorderStyle.None; @@ -64,13 +65,14 @@ protected override void OnDrawItem(DrawItemEventArgs e) string? text = _cursorConverter.ConvertToString(cursor); Font font = e.Font!; using var brushText = e.ForeColor.GetCachedSolidBrushScope(); + var cursorWidth = ScaleHelper.ScaleSmallIconToDpi(Icon.FromHandle(cursor.Handle), DeviceDpi).Size.Width; e.DrawBackground(); - e.Graphics.FillRectangle(SystemBrushes.Control, new Rectangle(e.Bounds.X + 2, e.Bounds.Y + 2, 32, e.Bounds.Height - 4)); - e.Graphics.DrawRectangle(SystemPens.WindowText, new Rectangle(e.Bounds.X + 2, e.Bounds.Y + 2, 32 - 1, e.Bounds.Height - 4 - 1)); + e.Graphics.FillRectangle(SystemBrushes.Control, new Rectangle(e.Bounds.X + 2, e.Bounds.Y + 2, cursorWidth, e.Bounds.Height - 4)); + e.Graphics.DrawRectangle(SystemPens.WindowText, new Rectangle(e.Bounds.X + 2, e.Bounds.Y + 2, cursorWidth - 1, e.Bounds.Height - 4 - 1)); - cursor.DrawStretched(e.Graphics, new Rectangle(e.Bounds.X + 2, e.Bounds.Y + 2, 32, e.Bounds.Height - 4)); - e.Graphics.DrawString(text, font, brushText, e.Bounds.X + 36, e.Bounds.Y + (e.Bounds.Height - font.Height) / 2); + cursor.DrawStretched(e.Graphics, new Rectangle(e.Bounds.X + 2, e.Bounds.Y + 2, cursorWidth, e.Bounds.Height - 4)); + e.Graphics.DrawString(text, font, brushText, e.Bounds.X + cursorWidth + 4, e.Bounds.Y + (e.Bounds.Height - font.Height) / 2); } }