diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ComboBox/ComboBox.FlatComboAdapter.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ComboBox/ComboBox.FlatComboAdapter.cs
index 56992511bdb..7146ddbd4bd 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ComboBox/ComboBox.FlatComboAdapter.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ComboBox/ComboBox.FlatComboAdapter.cs
@@ -23,9 +23,7 @@ internal class FlatComboAdapter
private const int OFFSET_2PIXELS = 2;
protected static int s_offsetPixels = OFFSET_2PIXELS;
- private bool ShouldRedrawAsSmallButton { get; }
-
- public FlatComboAdapter(ComboBox comboBox, bool shouldRedrawAsSmallButton)
+ public FlatComboAdapter(ComboBox comboBox, bool smallButton)
{
// adapter is re-created when ComboBox is resized, see IsValid method, thus we don't need to handle DPI changed explicitly
s_offsetPixels = comboBox.LogicalToDeviceUnits(OFFSET_2PIXELS);
@@ -37,10 +35,8 @@ public FlatComboAdapter(ComboBox comboBox, bool shouldRedrawAsSmallButton)
_innerInnerBorder = new Rectangle(_innerBorder.X + 1, _innerBorder.Y + 1, _innerBorder.Width - 2, _innerBorder.Height - 2);
_dropDownRect = new Rectangle(_innerBorder.Right + 1, _innerBorder.Y, dropDownButtonWidth, _innerBorder.Height + 1);
- ShouldRedrawAsSmallButton = shouldRedrawAsSmallButton;
-
// fill in several pixels of the dropdown rect with white so that it looks like the combo button is thinner.
- if (shouldRedrawAsSmallButton)
+ if (smallButton)
{
_whiteFillRect = _dropDownRect;
_whiteFillRect.Width = WhiteFillRectWidth;
@@ -64,48 +60,6 @@ public bool IsValid(ComboBox combo)
return (combo.ClientRectangle == _clientRect && combo.RightToLeft == _origRightToLeft);
}
- public virtual void DrawPopUpCombo(ComboBox comboBox, Graphics g)
- {
- if (comboBox.DropDownStyle == ComboBoxStyle.Simple)
- {
- return;
- }
-
- if (ShouldRedrawAsSmallButton)
- {
- DrawFlatCombo(comboBox, g);
- }
-
- bool rightToLeft = comboBox.RightToLeft == RightToLeft.Yes;
-
- // Draw a dark border around everything if we're in popup mode
- if ((!comboBox.Enabled) || (comboBox.FlatStyle == FlatStyle.Popup))
- {
- bool focused = comboBox.ContainsFocus || comboBox.MouseIsOver;
- Color borderPenColor = GetPopupOuterBorderColor(comboBox, focused);
-
- using var borderPen = borderPenColor.GetCachedPenScope();
- Pen innerPen = comboBox.Enabled ? borderPen : SystemPens.Control;
-
- // Draw a border around the dropdown.
- if (rightToLeft)
- {
- g.DrawRectangle(
- innerPen,
- new Rectangle(_outerBorder.X, _outerBorder.Y, _dropDownRect.Width + 1, _outerBorder.Height));
- }
- else
- {
- g.DrawRectangle(
- innerPen,
- new Rectangle(_dropDownRect.X, _outerBorder.Y, _outerBorder.Right - _dropDownRect.X, _outerBorder.Height));
- }
-
- // Draw a border around the whole ComboBox.
- g.DrawRectangle(borderPen, _outerBorder);
- }
- }
-
///
/// Paints over the edges of the combo box to make it appear flat.
///
@@ -153,6 +107,33 @@ public virtual void DrawFlatCombo(ComboBox comboBox, Graphics g)
using var innerBorderPen = innerBorderColor.GetCachedPenScope();
g.DrawRectangle(innerBorderPen, _innerBorder);
g.DrawRectangle(innerBorderPen, _innerInnerBorder);
+
+ // Draw a dark border around everything if we're in popup mode
+ if ((!comboBox.Enabled) || (comboBox.FlatStyle == FlatStyle.Popup))
+ {
+ bool focused = comboBox.ContainsFocus || comboBox.MouseIsOver;
+ Color borderPenColor = GetPopupOuterBorderColor(comboBox, focused);
+
+ using var borderPen = borderPenColor.GetCachedPenScope();
+ Pen innerPen = comboBox.Enabled ? borderPen : SystemPens.Control;
+
+ // Around the dropdown
+ if (rightToLeft)
+ {
+ g.DrawRectangle(
+ innerPen,
+ new Rectangle(_outerBorder.X, _outerBorder.Y, _dropDownRect.Width + 1, _outerBorder.Height));
+ }
+ else
+ {
+ g.DrawRectangle(
+ innerPen,
+ new Rectangle(_dropDownRect.X, _outerBorder.Y, _outerBorder.Right - _dropDownRect.X, _outerBorder.Height));
+ }
+
+ // Around the whole combobox.
+ g.DrawRectangle(borderPen, _outerBorder);
+ }
}
///
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ComboBox/ComboBox.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ComboBox/ComboBox.cs
index d078054db08..7355525d620 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ComboBox/ComboBox.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ComboBox/ComboBox.cs
@@ -3765,14 +3765,7 @@ protected override unsafe void WndProc(ref Message m)
}
using Graphics g = Graphics.FromHdcInternal((IntPtr)dc);
- if ((!Enabled || FlatStyle == FlatStyle.Popup) && MouseIsOver)
- {
- FlatComboBoxAdapter.DrawPopUpCombo(this, g);
- }
- else
- {
- FlatComboBoxAdapter.DrawFlatCombo(this, g);
- }
+ FlatComboBoxAdapter.DrawFlatCombo(this, g);
return;
}
@@ -3856,5 +3849,5 @@ private FlatComboAdapter FlatComboBoxAdapter
}
internal virtual FlatComboAdapter CreateFlatComboAdapterInstance()
- => new(this, shouldRedrawAsSmallButton: false);
+ => new(this, smallButton: false);
}
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolStripComboBox.ToolStripComboBoxControl.ToolStripComboBoxFlatComboAdapter.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolStripComboBox.ToolStripComboBoxControl.ToolStripComboBoxFlatComboAdapter.cs
index 571c11d5aa3..91ce6f35d68 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolStripComboBox.ToolStripComboBoxControl.ToolStripComboBoxFlatComboAdapter.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolStripComboBox.ToolStripComboBoxControl.ToolStripComboBoxFlatComboAdapter.cs
@@ -12,7 +12,7 @@ internal partial class ToolStripComboBoxControl : ComboBox
{
internal class ToolStripComboBoxFlatComboAdapter : FlatComboAdapter
{
- public ToolStripComboBoxFlatComboAdapter(ComboBox comboBox) : base(comboBox, shouldRedrawAsSmallButton: true)
+ public ToolStripComboBoxFlatComboAdapter(ComboBox comboBox) : base(comboBox, smallButton: true)
{
}