Skip to content

Commit f5fef93

Browse files
authored
Revert changes in PR11529 and PR11761 (#12737)
* Revert 11761 * Revert PR 11529
1 parent ce6b6c2 commit f5fef93

File tree

3 files changed

+32
-58
lines changed

3 files changed

+32
-58
lines changed

src/System.Windows.Forms/src/System/Windows/Forms/Controls/ComboBox/ComboBox.FlatComboAdapter.cs

+29-48
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ internal class FlatComboAdapter
2323
private const int OFFSET_2PIXELS = 2;
2424
protected static int s_offsetPixels = OFFSET_2PIXELS;
2525

26-
private bool ShouldRedrawAsSmallButton { get; }
27-
28-
public FlatComboAdapter(ComboBox comboBox, bool shouldRedrawAsSmallButton)
26+
public FlatComboAdapter(ComboBox comboBox, bool smallButton)
2927
{
3028
// adapter is re-created when ComboBox is resized, see IsValid method, thus we don't need to handle DPI changed explicitly
3129
s_offsetPixels = comboBox.LogicalToDeviceUnits(OFFSET_2PIXELS);
@@ -37,10 +35,8 @@ public FlatComboAdapter(ComboBox comboBox, bool shouldRedrawAsSmallButton)
3735
_innerInnerBorder = new Rectangle(_innerBorder.X + 1, _innerBorder.Y + 1, _innerBorder.Width - 2, _innerBorder.Height - 2);
3836
_dropDownRect = new Rectangle(_innerBorder.Right + 1, _innerBorder.Y, dropDownButtonWidth, _innerBorder.Height + 1);
3937

40-
ShouldRedrawAsSmallButton = shouldRedrawAsSmallButton;
41-
4238
// fill in several pixels of the dropdown rect with white so that it looks like the combo button is thinner.
43-
if (shouldRedrawAsSmallButton)
39+
if (smallButton)
4440
{
4541
_whiteFillRect = _dropDownRect;
4642
_whiteFillRect.Width = WhiteFillRectWidth;
@@ -64,48 +60,6 @@ public bool IsValid(ComboBox combo)
6460
return (combo.ClientRectangle == _clientRect && combo.RightToLeft == _origRightToLeft);
6561
}
6662

67-
public virtual void DrawPopUpCombo(ComboBox comboBox, Graphics g)
68-
{
69-
if (comboBox.DropDownStyle == ComboBoxStyle.Simple)
70-
{
71-
return;
72-
}
73-
74-
if (ShouldRedrawAsSmallButton)
75-
{
76-
DrawFlatCombo(comboBox, g);
77-
}
78-
79-
bool rightToLeft = comboBox.RightToLeft == RightToLeft.Yes;
80-
81-
// Draw a dark border around everything if we're in popup mode
82-
if ((!comboBox.Enabled) || (comboBox.FlatStyle == FlatStyle.Popup))
83-
{
84-
bool focused = comboBox.ContainsFocus || comboBox.MouseIsOver;
85-
Color borderPenColor = GetPopupOuterBorderColor(comboBox, focused);
86-
87-
using var borderPen = borderPenColor.GetCachedPenScope();
88-
Pen innerPen = comboBox.Enabled ? borderPen : SystemPens.Control;
89-
90-
// Draw a border around the dropdown.
91-
if (rightToLeft)
92-
{
93-
g.DrawRectangle(
94-
innerPen,
95-
new Rectangle(_outerBorder.X, _outerBorder.Y, _dropDownRect.Width + 1, _outerBorder.Height));
96-
}
97-
else
98-
{
99-
g.DrawRectangle(
100-
innerPen,
101-
new Rectangle(_dropDownRect.X, _outerBorder.Y, _outerBorder.Right - _dropDownRect.X, _outerBorder.Height));
102-
}
103-
104-
// Draw a border around the whole ComboBox.
105-
g.DrawRectangle(borderPen, _outerBorder);
106-
}
107-
}
108-
10963
/// <summary>
11064
/// Paints over the edges of the combo box to make it appear flat.
11165
/// </summary>
@@ -153,6 +107,33 @@ public virtual void DrawFlatCombo(ComboBox comboBox, Graphics g)
153107
using var innerBorderPen = innerBorderColor.GetCachedPenScope();
154108
g.DrawRectangle(innerBorderPen, _innerBorder);
155109
g.DrawRectangle(innerBorderPen, _innerInnerBorder);
110+
111+
// Draw a dark border around everything if we're in popup mode
112+
if ((!comboBox.Enabled) || (comboBox.FlatStyle == FlatStyle.Popup))
113+
{
114+
bool focused = comboBox.ContainsFocus || comboBox.MouseIsOver;
115+
Color borderPenColor = GetPopupOuterBorderColor(comboBox, focused);
116+
117+
using var borderPen = borderPenColor.GetCachedPenScope();
118+
Pen innerPen = comboBox.Enabled ? borderPen : SystemPens.Control;
119+
120+
// Around the dropdown
121+
if (rightToLeft)
122+
{
123+
g.DrawRectangle(
124+
innerPen,
125+
new Rectangle(_outerBorder.X, _outerBorder.Y, _dropDownRect.Width + 1, _outerBorder.Height));
126+
}
127+
else
128+
{
129+
g.DrawRectangle(
130+
innerPen,
131+
new Rectangle(_dropDownRect.X, _outerBorder.Y, _outerBorder.Right - _dropDownRect.X, _outerBorder.Height));
132+
}
133+
134+
// Around the whole combobox.
135+
g.DrawRectangle(borderPen, _outerBorder);
136+
}
156137
}
157138

158139
/// <summary>

src/System.Windows.Forms/src/System/Windows/Forms/Controls/ComboBox/ComboBox.cs

+2-9
Original file line numberDiff line numberDiff line change
@@ -3765,14 +3765,7 @@ protected override unsafe void WndProc(ref Message m)
37653765
}
37663766

37673767
using Graphics g = Graphics.FromHdcInternal((IntPtr)dc);
3768-
if ((!Enabled || FlatStyle == FlatStyle.Popup) && MouseIsOver)
3769-
{
3770-
FlatComboBoxAdapter.DrawPopUpCombo(this, g);
3771-
}
3772-
else
3773-
{
3774-
FlatComboBoxAdapter.DrawFlatCombo(this, g);
3775-
}
3768+
FlatComboBoxAdapter.DrawFlatCombo(this, g);
37763769

37773770
return;
37783771
}
@@ -3856,5 +3849,5 @@ private FlatComboAdapter FlatComboBoxAdapter
38563849
}
38573850

38583851
internal virtual FlatComboAdapter CreateFlatComboAdapterInstance()
3859-
=> new(this, shouldRedrawAsSmallButton: false);
3852+
=> new(this, smallButton: false);
38603853
}

src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolStripComboBox.ToolStripComboBoxControl.ToolStripComboBoxFlatComboAdapter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ internal partial class ToolStripComboBoxControl : ComboBox
1212
{
1313
internal class ToolStripComboBoxFlatComboAdapter : FlatComboAdapter
1414
{
15-
public ToolStripComboBoxFlatComboAdapter(ComboBox comboBox) : base(comboBox, shouldRedrawAsSmallButton: true)
15+
public ToolStripComboBoxFlatComboAdapter(ComboBox comboBox) : base(comboBox, smallButton: true)
1616
{
1717
}
1818

0 commit comments

Comments
 (0)