@@ -23,9 +23,7 @@ internal class FlatComboAdapter
23
23
private const int OFFSET_2PIXELS = 2 ;
24
24
protected static int s_offsetPixels = OFFSET_2PIXELS ;
25
25
26
- private bool ShouldRedrawAsSmallButton { get ; }
27
-
28
- public FlatComboAdapter ( ComboBox comboBox , bool shouldRedrawAsSmallButton )
26
+ public FlatComboAdapter ( ComboBox comboBox , bool smallButton )
29
27
{
30
28
// adapter is re-created when ComboBox is resized, see IsValid method, thus we don't need to handle DPI changed explicitly
31
29
s_offsetPixels = comboBox . LogicalToDeviceUnits ( OFFSET_2PIXELS ) ;
@@ -37,10 +35,8 @@ public FlatComboAdapter(ComboBox comboBox, bool shouldRedrawAsSmallButton)
37
35
_innerInnerBorder = new Rectangle ( _innerBorder . X + 1 , _innerBorder . Y + 1 , _innerBorder . Width - 2 , _innerBorder . Height - 2 ) ;
38
36
_dropDownRect = new Rectangle ( _innerBorder . Right + 1 , _innerBorder . Y , dropDownButtonWidth , _innerBorder . Height + 1 ) ;
39
37
40
- ShouldRedrawAsSmallButton = shouldRedrawAsSmallButton ;
41
-
42
38
// 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 )
44
40
{
45
41
_whiteFillRect = _dropDownRect ;
46
42
_whiteFillRect . Width = WhiteFillRectWidth ;
@@ -64,48 +60,6 @@ public bool IsValid(ComboBox combo)
64
60
return ( combo . ClientRectangle == _clientRect && combo . RightToLeft == _origRightToLeft ) ;
65
61
}
66
62
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
-
109
63
/// <summary>
110
64
/// Paints over the edges of the combo box to make it appear flat.
111
65
/// </summary>
@@ -153,6 +107,33 @@ public virtual void DrawFlatCombo(ComboBox comboBox, Graphics g)
153
107
using var innerBorderPen = innerBorderColor . GetCachedPenScope ( ) ;
154
108
g . DrawRectangle ( innerBorderPen , _innerBorder ) ;
155
109
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
+ }
156
137
}
157
138
158
139
/// <summary>
0 commit comments