Skip to content

Commit 504b21a

Browse files
Fix bug where a dedicated Toolstrip Renderer would not be called for background painting.
1 parent 2153282 commit 504b21a

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3636,6 +3636,7 @@ protected override void OnPaintBackground(PaintEventArgs e)
36363636

36373637
Graphics g = e.GraphicsInternal;
36383638
GraphicsState graphicsState = g.Save();
3639+
36393640
try
36403641
{
36413642
using (Region? transparentRegion = Renderer.GetTransparentRegion(this))
@@ -3647,6 +3648,12 @@ protected override void OnPaintBackground(PaintEventArgs e)
36473648
}
36483649
}
36493650

3651+
if (Renderer.RendererOverride is ToolStripRenderer renderer)
3652+
{
3653+
renderer.DrawToolStripBackground(new ToolStripRenderEventArgs(g, this));
3654+
return;
3655+
}
3656+
36503657
Renderer.DrawToolStripBackground(new ToolStripRenderEventArgs(g, this));
36513658
}
36523659
finally

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ internal ToolStripSystemDarkModeRenderer(bool isDefault) : base(isDefault)
3939
/// <returns>A color suitable for dark mode.</returns>
4040
private static Color GetDarkModeColor(Color color)
4141
{
42-
// Map common system colors to their dark mode equivalents
42+
// Map system colors to some slightly different colors we would get
43+
// form the actual system colors in dark mode, since the visual style
44+
// renderer in light mode would also not "hit" (for contrast and styling
45+
// reasons) the exact same palette settings as the system colors.
4346
if (color == SystemColors.Control)
4447
return Color.FromArgb(45, 45, 45);
4548
if (color == SystemColors.ControlLight)
@@ -107,15 +110,7 @@ private static Pen GetDarkModePen(Color color)
107110
/// <param name="toolStrip">The ToolStrip to check.</param>
108111
/// <returns>true if the background should be painted; otherwise, false.</returns>
109112
private static bool ShouldPaintBackground(ToolStrip toolStrip)
110-
{
111-
if (toolStrip is null)
112-
return true;
113-
114-
if (toolStrip.BackgroundImage is not null)
115-
return false;
116-
117-
return true;
118-
}
113+
=> toolStrip is null || toolStrip.BackgroundImage is null;
119114

120115
/// <summary>
121116
/// Fills the background with the specified color.

0 commit comments

Comments
 (0)