Skip to content

Commit 6da3eca

Browse files
Leaf ShiLeaf Shi
authored andcommitted
Put DrawButtonBorder after PaintImage and removing the rounded border in Flat mode
1 parent 3fa5fe4 commit 6da3eca

File tree

5 files changed

+11
-15
lines changed

5 files changed

+11
-15
lines changed

src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/ButtonInternal/ButtonBaseAdapter.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -549,15 +549,13 @@ internal void PaintImage(PaintEventArgs e, LayoutData layout)
549549
{
550550
if (Application.IsDarkModeEnabled && Control.DarkModeRequestState is true && Control.BackgroundImage is not null)
551551
{
552-
Rectangle bounds = Control.ClientRectangle;
553-
bounds.Inflate(-ButtonBorderSize, -ButtonBorderSize);
554552
ControlPaint.DrawBackgroundImage(
555553
e.GraphicsInternal,
556554
Control.BackgroundImage,
557555
Color.Transparent,
558556
Control.BackgroundImageLayout,
559557
Control.ClientRectangle,
560-
bounds,
558+
Control.ClientRectangle,
561559
Control.DisplayRectangle.Location,
562560
Control.RightToLeft);
563561
}

src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/ButtonInternal/DarkMode/ButtonDarkModeRendererBase.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ public void RenderButton(
6666
// Paint image and field using the provided delegates
6767
paintImage(contentBounds);
6868

69+
DrawButtonBorder(graphics, bounds, state, isDefault);
70+
6971
paintField();
7072

7173
if (focused && showFocusCues)
@@ -76,6 +78,8 @@ public void RenderButton(
7678
}
7779
}
7880

81+
public abstract void DrawButtonBorder(Graphics graphics, Rectangle bounds, PushButtonState state, bool isDefault);
82+
7983
public abstract Rectangle DrawButtonBackground(Graphics graphics, Rectangle bounds, PushButtonState state, bool isDefault, Color backColor);
8084

8185
public abstract void DrawFocusIndicator(Graphics graphics, Rectangle contentBounds, bool isDefault);

src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/ButtonInternal/DarkMode/FlatButtonDarkModeRenderer.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ namespace System.Windows.Forms;
1717
internal sealed class FlatButtonDarkModeRenderer : ButtonDarkModeRendererBase
1818
{
1919
private const int FocusIndicatorInflate = -3;
20-
private const int CornerRadius = 6;
21-
private static readonly Size s_corner = new(CornerRadius, CornerRadius);
2220

2321
private protected override Padding PaddingCore { get; } = new(0);
2422

@@ -28,10 +26,6 @@ public override Rectangle DrawButtonBackground(
2826
// fill background
2927
using var back = backColor.GetCachedSolidBrushScope();
3028
graphics.FillRectangle(back, bounds);
31-
32-
// draw border identical to Win32
33-
DrawButtonBorder(graphics, bounds, state, isDefault);
34-
3529
// return inner content area (border + 1 px system padding)
3630
return Rectangle.Inflate(bounds, -3, -3);
3731
}
@@ -77,7 +71,7 @@ public override Color GetBackgroundColor(PushButtonState state, bool isDefault)
7771
_ => DefaultColors.StandardBackColor
7872
};
7973

80-
private static void DrawButtonBorder(Graphics g, Rectangle bounds, PushButtonState state, bool isDefault)
74+
public override void DrawButtonBorder(Graphics g, Rectangle bounds, PushButtonState state, bool isDefault)
8175
{
8276
g.SmoothingMode = SmoothingMode.AntiAlias;
8377

@@ -98,12 +92,9 @@ private static void DrawSingleBorder(Graphics g, Rectangle rect, Color color)
9892
{
9993
g.SmoothingMode = SmoothingMode.AntiAlias;
10094

101-
using var path = new GraphicsPath();
102-
path.AddRoundedRectangle(rect, s_corner);
103-
10495
// a 1‑px stroke, aligned *inside*, is exactly what Win32 draws
10596
using var pen = new Pen(color) { Alignment = PenAlignment.Inset };
106-
g.DrawPath(pen, path);
97+
g.DrawRectangle(pen, rect);
10798
}
10899

109100
private static Color GetBorderColor(PushButtonState state) =>

src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/ButtonInternal/DarkMode/PopupButtonDarkModeRenderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public override Color GetBackgroundColor(PushButtonState state, bool isDefault)
120120
/// <summary>
121121
/// Draws the 3D effect border for the button.
122122
/// </summary>
123-
private static void DrawButtonBorder(Graphics graphics, Rectangle bounds, PushButtonState state, bool isDefault)
123+
public override void DrawButtonBorder(Graphics graphics, Rectangle bounds, PushButtonState state, bool isDefault)
124124
{
125125
// Save original smoothing mode to restore later
126126
SmoothingMode originalMode = graphics.SmoothingMode;

src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/ButtonInternal/DarkMode/SystemButtonDarkModeRenderer.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ public override Color GetBackgroundColor(PushButtonState state, bool isDefault)
108108
_ => DefaultColors.StandardBackColor
109109
};
110110

111+
public override void DrawButtonBorder(Graphics graphics, Rectangle bounds, PushButtonState state, bool isDefault) =>
112+
DrawButtonBorder(graphics, bounds, state, isDefault, false);
113+
111114
/// <summary>
112115
/// Draws the button border based on the current state, using anti-aliasing and an additional inner border.
113116
/// </summary>

0 commit comments

Comments
 (0)