Skip to content

Commit b36858f

Browse files
authored
Add focused state for DropDownButton and reduces the icon width of the dropdown model button (#13773)
<!-- Please read CONTRIBUTING.md before submitting a pull request --> Fixes #13766, #13765 ## Proposed changes - Added a Focused state to the property page's drop-down button. - Reduces the icon width of the model button. <!-- We are in TELL-MODE the following section must be completed --> ## Customer Impact - The drop-down button of the Property page can be focused under DarkMode ## Regression? - Yes ## Risk - Minimal <!-- end TELL-MODE --> ## Screenshots <!-- Remove this section if PR does not change UI --> ### Before Dropdown arrow and ellipse symbol in PropertyGrid appears larger in DarkMode and the focus indicator (e.g., dotted line or outline) is not visible when navigating to the DropDownButton or Ellipse Button controls by keyboard Dark mode on 100% DPI: <img width="468" height="42" alt="image" src="https://github.com/user-attachments/assets/7f556f54-f4d7-43bd-a37f-bb6722cc7c90" /> <img width="462" height="66" alt="image" src="https://github.com/user-attachments/assets/29044324-78a6-4ae7-b396-10c8e1228d50" /> Dark mode on 250% DPI: <img width="1377" height="112" alt="image" src="https://github.com/user-attachments/assets/038bab90-10b9-4f9b-9d61-dde7ab72edb2" /> <img width="1391" height="106" alt="image" src="https://github.com/user-attachments/assets/5427dd45-fba3-47ca-b9fe-6db0387df029" /> ### After The dropdown arrow appears normal and it can be focued 100% DPI: <img width="468" height="63" alt="image" src="https://github.com/user-attachments/assets/e2eadd54-eef3-4b62-a78e-8cf5d12eb176" /> <img width="493" height="82" alt="image" src="https://github.com/user-attachments/assets/ce2250c8-bcd8-4d2c-b2ad-5abb4d6b394a" /> 250% DPI: <img width="857" height="120" alt="image" src="https://github.com/user-attachments/assets/960221c6-e1cf-4645-b2fe-af9b638b7c0c" /> <img width="1112" height="171" alt="image" src="https://github.com/user-attachments/assets/b589a411-a7d4-4c36-a873-2ca1359d0400" /> ## Test methodology <!-- How did you ensure quality? --> - manually ## Test environment(s) <!-- Remove any that don't apply --> - .net 10.0.0-preview.7.25377.103 <!-- Mention language, UI scaling, or anything else that might be relevant --> ###### Microsoft Reviewers: [Open in CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/dotnet/winforms/pull/13773)
2 parents 47e9815 + 38e7fda commit b36858f

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)