Skip to content

Commit f65907a

Browse files
Fix subtle bug in the SystemRenderer base class, and...
...proof, that the existing Unit Tests are doing a fantastic job!
1 parent 5dff9f8 commit f65907a

File tree

4 files changed

+45
-51
lines changed

4 files changed

+45
-51
lines changed

src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/ToolStrip.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3250,7 +3250,7 @@ protected override void OnLayout(LayoutEventArgs e)
32503250
{
32513251
LayoutRequired = false;
32523252

3253-
// we need to do this to prevent autosizing to happen while we're reparenting.
3253+
// we need to do this to prevent auto-sizing to happen while we're reparenting.
32543254
ToolStripOverflow? overflow = GetOverflow();
32553255
if (overflow is not null)
32563256
{
@@ -3648,12 +3648,6 @@ protected override void OnPaintBackground(PaintEventArgs e)
36483648
}
36493649
}
36503650

3651-
if (Renderer.RendererOverride is ToolStripRenderer renderer)
3652-
{
3653-
renderer.DrawToolStripBackground(new ToolStripRenderEventArgs(g, this));
3654-
return;
3655-
}
3656-
36573651
Renderer.DrawToolStripBackground(new ToolStripRenderEventArgs(g, this));
36583652
}
36593653
finally

src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/ToolStripRenderer.cs

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,16 @@ public abstract class ToolStripRenderer
5656
// status strip sizing grip.
5757
private static readonly Rectangle[] s_baseSizeGripRectangles =
5858
[
59-
new(8, 0, 2, 2),
59+
new(12, 0, 2, 2),
6060
new(8, 4, 2, 2),
61-
new(8, 8, 2, 2),
62-
new(4, 4, 2, 2),
6361
new(4, 8, 2, 2),
64-
new(0, 8, 2, 2)
62+
new(0, 12, 2, 2),
63+
new(8, 0, 2, 2),
64+
new(4, 4, 2, 2),
65+
new(0, 8, 2, 2),
66+
new(4, 0, 2, 2),
67+
new(0, 4, 2, 2),
68+
new(1, 1, 2, 2),
6569
];
6670

6771
protected ToolStripRenderer()
@@ -1064,60 +1068,59 @@ private protected void OnRenderStatusStripSizingGrip(
10641068
Math.Max((int)(r.Height * dpiScale), 2));
10651069
}
10661070

1071+
(int cornerOffset, Rectangle lastRect) = GetCornerOffset(statusStrip);
1072+
scaledRects[^1] = lastRect;
1073+
10671074
SmoothingMode oldSmoothing = g.SmoothingMode;
10681075
g.SmoothingMode = SmoothingMode.AntiAlias;
10691076

1070-
int cornerOffset = GetCornerOffset(statusStrip);
1071-
10721077
// Draw the grip dots, bottom-right aligned (mirrored for RTL)
10731078
foreach (Rectangle dotRect in scaledRects)
10741079
{
1075-
Rectangle actualRect;
1076-
if (statusStrip.RightToLeft == RightToLeft.Yes)
1077-
{
1078-
actualRect = new Rectangle(
1079-
sizeGripBounds.Left + cornerOffset + dotRect.X,
1080-
sizeGripBounds.Bottom - cornerOffset - dotRect.Y - dotRect.Height,
1081-
dotRect.Width,
1082-
dotRect.Height);
1083-
}
1084-
else
1085-
{
1086-
actualRect = new Rectangle(
1087-
sizeGripBounds.Right - cornerOffset - dotRect.X - dotRect.Width,
1088-
sizeGripBounds.Bottom - cornerOffset - dotRect.Y - dotRect.Height,
1089-
dotRect.Width,
1090-
dotRect.Height);
1091-
}
1080+
Rectangle actualRect = statusStrip.RightToLeft == RightToLeft.Yes
1081+
? new Rectangle(
1082+
x: sizeGripBounds.Left + cornerOffset + dotRect.X,
1083+
y: sizeGripBounds.Bottom - cornerOffset - dotRect.Y - dotRect.Height,
1084+
width: dotRect.Width,
1085+
height: dotRect.Height)
1086+
1087+
: new Rectangle(
1088+
x: sizeGripBounds.Right - cornerOffset - dotRect.X - dotRect.Width,
1089+
y: sizeGripBounds.Bottom - cornerOffset - dotRect.Y - dotRect.Height,
1090+
width: dotRect.Width,
1091+
height: dotRect.Height);
10921092

10931093
// Highlight dot (top-left)
10941094
Rectangle highlightRect = actualRect;
10951095
highlightRect.Offset(-1, -1);
1096+
10961097
g.FillEllipse(highLightBrush, highlightRect);
10971098

10981099
// Shadow dot (bottom-right)
10991100
Rectangle shadowRect = actualRect;
11001101
shadowRect.Offset(1, 1);
1102+
11011103
g.FillEllipse(shadowBrush, shadowRect);
11021104
}
11031105

11041106
g.SmoothingMode = oldSmoothing;
11051107

1106-
static int GetCornerOffset(StatusStrip statusStrip)
1108+
static (int cornerOffset, Rectangle rect) GetCornerOffset(StatusStrip statusStrip)
11071109
{
1108-
int cornerOffset = 0;
1110+
(int, Rectangle) cornerDef = (2, new(1, 1, 2, 2));
1111+
11091112
if (Environment.OSVersion.Version >= new Version(10, 0, 22000)
11101113
&& statusStrip.FindForm() is Form f)
11111114
{
1112-
cornerOffset = f.FormCornerPreference switch
1115+
cornerDef = f.FormCornerPreference switch
11131116
{
1114-
FormCornerPreference.Round => 5,
1115-
FormCornerPreference.RoundSmall => 3,
1116-
_ => 3
1117+
FormCornerPreference.Round => (4, new(1, 1, 2, 2)),
1118+
FormCornerPreference.RoundSmall => (3, new(1, 1, 2, 2)),
1119+
_ => (2, new(0, 0, 2, 2))
11171120
};
11181121
}
11191122

1120-
return cornerOffset;
1123+
return cornerDef;
11211124
}
11221125
}
11231126

src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/ToolStripSystemDarkModeRenderer.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -677,11 +677,8 @@ protected override void OnRenderStatusStripSizingGrip(ToolStripRenderEventArgs e
677677
{
678678
ArgumentNullException.ThrowIfNull(e);
679679

680-
// Color choice here is not a mistake. The shadow effect in dark mode is
681-
// not made of the complementary "colors" of light mode. That doesn't give
682-
// enough contrast for an effect to actually spot.
683-
using var highLightBrush = GetDarkModeBrush(SystemColors.ButtonShadow);
684-
using var shadowBrush = GetDarkModeBrush(SystemColors.GrayText);
680+
using var highLightBrush = GetDarkModeBrush(SystemColors.GrayText);
681+
using var shadowBrush = GetDarkModeBrush(SystemColors.ButtonShadow);
685682

686683
OnRenderStatusStripSizingGrip(
687684
eArgs: e,

src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/ToolStripSystemRenderer.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ internal ToolStripRenderer HighContrastRenderer
3939
{
4040
get
4141
{
42-
_toolStripHighContrastRenderer ??= new ToolStripHighContrastRenderer(/*renderLikeSystem*/true);
42+
_toolStripHighContrastRenderer ??= new ToolStripHighContrastRenderer(systemRenderMode: false);
4343
return _toolStripHighContrastRenderer;
4444
}
4545
}
@@ -51,7 +51,7 @@ internal ToolStripRenderer DarkModeRenderer
5151
{
5252
get
5353
{
54-
_toolStripDarkModeRenderer ??= new ToolStripSystemDarkModeRenderer();
54+
_toolStripDarkModeRenderer ??= new ToolStripSystemDarkModeRenderer(isDefault: false);
5555
return _toolStripDarkModeRenderer;
5656
}
5757
}
@@ -240,18 +240,18 @@ protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e)
240240
else if (DisplayInformation.LowResolution)
241241
{
242242
FillBackground(g, bounds, (toolStrip is ToolStripDropDown)
243-
? SystemColors.ControlLight
244-
: e.BackColor);
243+
? e.BackColor
244+
: SystemColors.ControlLight);
245245
}
246246
else if (toolStrip.IsDropDown)
247247
{
248-
FillBackground(g, bounds, ToolStripManager.VisualStylesEnabled
248+
FillBackground(g, bounds, (!ToolStripManager.VisualStylesEnabled)
249249
? SystemColors.Menu
250250
: e.BackColor);
251251
}
252252
else if (toolStrip is MenuStrip)
253253
{
254-
FillBackground(g, bounds, ToolStripManager.VisualStylesEnabled
254+
FillBackground(g, bounds, (!ToolStripManager.VisualStylesEnabled)
255255
? SystemColors.MenuBar
256256
: e.BackColor);
257257
}
@@ -264,9 +264,9 @@ protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e)
264264
}
265265
else
266266
{
267-
FillBackground(g, bounds, ToolStripManager.VisualStylesEnabled
268-
? SystemColors.MenuBar
269-
: e.BackColor);
267+
FillBackground(g, bounds, (!ToolStripManager.VisualStylesEnabled)
268+
? e.BackColor
269+
: SystemColors.MenuBar);
270270
}
271271
}
272272
}

0 commit comments

Comments
 (0)