Skip to content

Commit 38e7fda

Browse files
committed
Add focused state for DropDownButton and reduces the icon width of the dropdown model button
1 parent 7c9d043 commit 38e7fda

File tree

5 files changed

+27
-5
lines changed

5 files changed

+27
-5
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
System.Windows.Forms.VisualStyles.ComboBoxState.Focused = 5 -> System.Windows.Forms.VisualStyles.ComboBoxState

src/System.Windows.Forms/System/Windows/Forms/Controls/PropertyGrid/PropertyGridInternal/DropDownButton.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,22 @@ protected override void OnPaint(PaintEventArgs pevent)
8383
{
8484
ComboBoxState state = ComboBoxState.Normal;
8585

86-
if (MouseIsDown)
86+
if (!Enabled)
87+
{
88+
state = ComboBoxState.Disabled;
89+
}
90+
else if (MouseIsDown)
8791
{
8892
state = ComboBoxState.Pressed;
8993
}
9094
else if (MouseIsOver)
9195
{
9296
state = ComboBoxState.Hot;
9397
}
98+
else if (Focused)
99+
{
100+
state = ComboBoxState.Focused;
101+
}
94102

95103
base.OnPaint(pevent);
96104

@@ -101,6 +109,7 @@ protected override void OnPaint(PaintEventArgs pevent)
101109
ComboBoxState.Disabled => ModernControlButtonState.Disabled,
102110
ComboBoxState.Hot => ModernControlButtonState.Hover,
103111
ComboBoxState.Pressed => ModernControlButtonState.Pressed,
112+
ComboBoxState.Focused => ModernControlButtonState.Focused,
104113
_ => ModernControlButtonState.Normal
105114
};
106115

src/System.Windows.Forms/System/Windows/Forms/Rendering/ControlPaint.ModernControlButtonState.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ internal enum ModernControlButtonState
1010
Normal,
1111
Disabled,
1212
Pressed,
13-
Hover
13+
Hover,
14+
Focused
1415
}
1516
}

src/System.Windows.Forms/System/Windows/Forms/Rendering/ControlPaint_ModernControlButtonRenderer.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ internal static void DrawModernControlButton(
9191

9292
bool hasRoundedBorder = (button & ModernControlButtonStyle.RoundedBorder) != 0;
9393

94+
bool isFocused = state == ModernControlButtonState.Focused;
95+
9496
// Draw background
9597
using (var backgroundBrush = backgroundColor.GetCachedSolidBrushScope())
9698
{
@@ -121,6 +123,14 @@ internal static void DrawModernControlButton(
121123
}
122124
}
123125

126+
if (isFocused)
127+
{
128+
// Draw focus rectangle
129+
Rectangle focusRect = bounds;
130+
focusRect.Inflate(-1, -1); // Deflate to avoid drawing over the border
131+
DrawFocusRectangle(graphics, focusRect, Color.Empty, backgroundColor);
132+
}
133+
124134
// Draw the content
125135
ModernControlButtonStyle contentType = button
126136
& ~(ModernControlButtonStyle.SingleBorder
@@ -280,7 +290,7 @@ private static void DrawEllipseSymbol(Graphics graphics, Brush brush, int center
280290
{
281291
// Calculate dot size as a proportion of button height
282292
int minDimension = Math.Min(bounds.Width, bounds.Height);
283-
int dotSize = Math.Max(1, (int)(minDimension * 0.15 * ContentScaleFactor));
293+
int dotSize = Math.Max(1, (int)(minDimension * 0.1 * ContentScaleFactor));
284294

285295
// Calculate proportional spacing
286296
int spacing = Math.Max(1, dotSize / 2);
@@ -310,7 +320,7 @@ private static void DrawEllipseSymbol(Graphics graphics, Brush brush, int center
310320
private static void DrawOpenDropDownChevron(Graphics graphics, Brush brush, int centerX, int centerY, int size)
311321
{
312322
// Calculate chevron dimensions proportionally
313-
int chevronWidth = size + (size / 2);
323+
int chevronWidth = size;
314324
int chevronHeight = (size * 2) / 3;
315325

316326
// Stroke thickness scales with size

src/System.Windows.Forms/System/Windows/Forms/VisualStyles/ComboBoxState.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ public enum ComboBoxState
88
Normal = 1,
99
Hot = 2,
1010
Pressed = 3,
11-
Disabled = 4
11+
Disabled = 4,
12+
Focused = 5,
1213
}

0 commit comments

Comments
 (0)