Skip to content

Commit 3cd024d

Browse files
Epica3055LeafShi1
authored andcommitted
fix: Border of SplitButton of ToolStrip is not contrasting enough … (#12092)
* fix: Border of SplitButton of ToolStrip is not contrasting enough in High Contrast theme #12083
1 parent dfceb98 commit 3cd024d

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,9 @@ protected override void OnRenderSplitButtonBackground(ToolStripItemRenderEventAr
146146
else if (item.Selected)
147147
{
148148
g.FillRectangle(SystemBrushes.Highlight, bounds);
149+
g.DrawRectangle(SystemPens.HighlightText, dropDownRect);
150+
149151
DrawHightContrastDashedBorder(g, e.Item);
150-
g.DrawRectangle(SystemPens.ButtonHighlight, dropDownRect);
151152
}
152153

153154
Color arrowColor = item.Selected && !item.Pressed ? SystemColors.HighlightText : SystemColors.ControlText;

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,17 @@ protected override void OnRenderSplitButtonBackground(ToolStripItemRenderEventAr
575575
{
576576
DrawArrow(new ToolStripArrowRenderEventArgs(g, splitButton, splitButton.DropDownButtonBounds, arrowColor, ArrowDirection.Down));
577577
}
578+
579+
ToolBarState state = GetToolBarState(e.Item);
580+
if (e.Item is ToolStripSplitButton item && !SystemInformation.HighContrast &&
581+
(state == ToolBarState.Hot || state == ToolBarState.Pressed || state == ToolBarState.Checked))
582+
{
583+
var clientBounds = item.ClientBounds;
584+
bounds.Height -= 1;
585+
ControlPaint.DrawBorderSimple(g, clientBounds, SystemColors.Highlight);
586+
using var brush = SystemColors.Highlight.GetCachedSolidBrushScope();
587+
g.FillRectangle(brush, item.SplitterBounds);
588+
}
578589
}
579590
else
580591
{

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,10 @@ protected override void OnRenderSplitButtonBackground(ToolStripItemRenderEventAr
296296

297297
if (buttonPressedOrSelected && !item.Pressed)
298298
{
299-
using var brush = ColorTable.ButtonSelectedBorder.GetCachedSolidBrushScope();
299+
#pragma warning disable WFO5001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
300+
using var brush = Application.IsDarkModeEnabled ?
301+
Color.Silver.GetCachedSolidBrushScope() : ColorTable.ButtonSelectedBorder.GetCachedSolidBrushScope();
302+
#pragma warning restore WFO5001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
300303
g.FillRectangle(brush, item.SplitterBounds);
301304
}
302305

src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripButtonTests.Rendering.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,9 @@ public void ToolStripButton_SplitButton_Selected_RendersBackgroundCorrectly_High
162162
bounds: null,
163163
points: null,
164164
State.Brush(SystemColors.Highlight, BRUSH_STYLE.BS_SOLID)),
165+
Validate.SkipType(ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYGON16),
165166
Validate.Repeat(Validate.SkipType(ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYPOLYGON16), 2),
166-
Validate.Repeat(Validate.SkipType(ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYGON16), 2));
167+
Validate.SkipType(ENHANCED_METAFILE_RECORD_TYPE.EMR_POLYGON16));
167168
}
168169

169170
private class ToolStripSystemHighContrastRenderer : ToolStripSystemRenderer

0 commit comments

Comments
 (0)