@@ -12,20 +12,17 @@ namespace System.Windows.Forms;
12
12
/// </summary>
13
13
internal static partial class ButtonDarkModeRenderer
14
14
{
15
- // Magic numbers extracted as constants or static properties
16
- private const int DefaultPaddingValue = 2 ;
17
-
18
15
// Singleton instances for each renderer type
19
16
internal static IButtonDarkModeRenderer StandardRenderer { get ; } = new StandardButtonDarkModeRenderer ( ) ;
20
17
internal static IButtonDarkModeRenderer FlatRenderer { get ; } = new FlatButtonDarkModeRenderer ( ) ;
21
18
internal static IButtonDarkModeRenderer PopupRenderer { get ; } = new PopupButtonDarkModeRenderer ( ) ;
22
19
internal static IButtonDarkModeRenderer SystemRenderer { get ; } = new SystemButtonDarkModeRenderer ( ) ;
23
20
24
21
// Define padding values for each renderer type
25
- internal static Padding StandardPaddingCore { get ; } = new ( DefaultPaddingValue ) ;
26
- internal static Padding FlatPaddingCore { get ; } = new ( DefaultPaddingValue ) ;
27
- internal static Padding PopupPaddingCore { get ; } = new ( DefaultPaddingValue ) ;
28
- internal static Padding SystemPaddingCore { get ; } = new ( DefaultPaddingValue ) ;
22
+ internal static Padding StandardPaddingCore { get ; } = new ( 0 ) ;
23
+ internal static Padding FlatPaddingCore { get ; } = new ( 0 ) ;
24
+ internal static Padding PopupPaddingCore { get ; } = new ( 0 ) ;
25
+ internal static Padding SystemPaddingCore { get ; } = new ( 0 ) ;
29
26
30
27
/// <summary>
31
28
/// Returns the appropriate padding for the specified flat style.
@@ -52,13 +49,8 @@ public static void DrawButtonBorder(Graphics graphics, GraphicsPath path, Color
52
49
/// Clears the background with the parent's background color or the control's background color if no parent is available.
53
50
/// </summary>
54
51
/// <param name="graphics">Graphics context to draw on</param>
55
- /// <param name="bounds">Bounds of the area to clear</param>
56
- private static void ClearBackground ( Graphics graphics , Rectangle bounds , Color parentBackgroundColor )
57
- {
58
- // Clear the background with the determined color
59
- using var brush = parentBackgroundColor . GetCachedSolidBrushScope ( ) ;
60
- graphics . FillRectangle ( brush , bounds ) ;
61
- }
52
+ private static void ClearBackground ( Graphics graphics , Color parentBackgroundColor ) =>
53
+ graphics . Clear ( parentBackgroundColor ) ;
62
54
63
55
/// <summary>
64
56
/// Renders a button with the specified properties and delegates for painting image and field.
@@ -84,24 +76,43 @@ internal static void RenderButton(
84
76
} ;
85
77
86
78
// Background over the whole Button area needs to be cleared in any case.
87
- ClearBackground ( graphics , bounds , parentBackgroundColor ) ;
79
+ ClearBackground ( graphics , parentBackgroundColor ) ;
88
80
89
81
// Use padding from ButtonDarkModeRenderer
90
82
Padding padding = GetPaddingCore ( FlatStyle . System ) ;
91
- Rectangle paddedBounds = Rectangle . Inflate ( bounds , - padding . Left , - padding . Top ) ;
83
+ Rectangle paddedBounds = new (
84
+ x : bounds . X + padding . Left ,
85
+ y : bounds . Y + padding . Top ,
86
+ width : bounds . Width - padding . Horizontal ,
87
+ height : bounds . Height - padding . Vertical ) ;
92
88
93
89
// Draw button background and get content bounds
94
90
Rectangle contentBounds = renderer . DrawButtonBackground ( graphics , paddedBounds , state , isDefault ) ;
95
91
92
+ // Offset content bounds for Popup style when button is pressed
93
+ if ( flatStyle == FlatStyle . Popup && state == PushButtonState . Pressed )
94
+ {
95
+ contentBounds . Offset ( 1 , 1 ) ;
96
+ }
97
+
96
98
// Paint image and field using the provided delegates
97
99
paintImage ( contentBounds ) ;
100
+
98
101
paintField (
99
102
contentBounds ,
100
103
renderer . GetTextColor ( state , isDefault ) ,
101
104
false ) ;
102
105
106
+ if ( focused && flatStyle == FlatStyle . System )
107
+ {
108
+ // Focus with the system renderer is completely surrounded by a border.
109
+ renderer . DrawFocusIndicator ( graphics , bounds , isDefault ) ;
110
+ return ;
111
+ }
112
+
103
113
if ( focused && showFocusCues )
104
114
{
115
+ // Draw focus indicator for other styles
105
116
renderer . DrawFocusIndicator ( graphics , contentBounds , isDefault ) ;
106
117
}
107
118
}
0 commit comments