@@ -20,24 +20,11 @@ public class ScrollBarEx : Control
20
20
{
21
21
#region scroll bar settings
22
22
23
- public delegate void SettingsChangedEventHandler ( ScrollBarMode value ) ;
24
- public static event SettingsChangedEventHandler SettingsChanged ;
25
-
26
- public static ScrollBarMode SettingsMode
27
- {
28
- get { return PluginBase . MainForm . Settings . UseCustomScrollBar ; }
29
- }
30
-
31
23
public static bool UseCustom
32
24
{
33
25
get { return PluginBase . MainForm . GetThemeValue ( "ScrollBar.UseCustom" , "false" ) . ToLower ( ) == "true" ; }
34
26
}
35
27
36
- public static void NotifySettingsChanged ( ScrollBarMode value )
37
- {
38
- if ( SettingsChanged != null ) SettingsChanged . Invoke ( value ) ;
39
- }
40
-
41
28
#endregion
42
29
43
30
#region drawing
@@ -53,7 +40,7 @@ public static void NotifySettingsChanged(ScrollBarMode value)
53
40
private Color backColorDisabled /* = SystemColors.ControlLight*/ ;
54
41
private Color borderColor /* = SystemColors.ActiveBorder*/ ;
55
42
private Color borderColorDisabled /* = SystemColors.Control*/ ;
56
- private bool colorsInvalidated ;
43
+ private Boolean colorsInvalidated = false ;
57
44
58
45
/// <summary>
59
46
/// Resets the component colors to default values.
@@ -86,14 +73,14 @@ public void ValidateColors()
86
73
// Reset any unassigned colors to default.
87
74
InitializeColors ( ) ;
88
75
89
- // If no colors are explicitly defined, not fallback colors are required.
76
+ // If no colors are explicitly defined, no fallback colors are required.
90
77
if ( ! colorsInvalidated ) return ;
91
78
92
79
// Newly introduced color options - do not assign default colors. Instead fall back to associated colors.
93
- foreColorHot = PluginBase . MainForm . GetThemeColor ( "ScrollBar.HotForeColor" , foreColor ) ;
94
- arrowColor = PluginBase . MainForm . GetThemeColor ( "ScrollBar.ArrowColor" , foreColor ) ;
95
- arrowColorHot = PluginBase . MainForm . GetThemeColor ( "ScrollBar.HotArrowColor" , arrowColor ) ;
96
- arrowColorPressed = PluginBase . MainForm . GetThemeColor ( "ScrollBar.ActiveArrowColor" , foreColorPressed ) ;
80
+ if ( foreColorHot . IsEmpty ) foreColorHot = PluginBase . MainForm . GetThemeColor ( "ScrollBar.HotForeColor" , foreColor ) ;
81
+ if ( arrowColor . IsEmpty ) arrowColor = PluginBase . MainForm . GetThemeColor ( "ScrollBar.ArrowColor" , foreColor ) ;
82
+ if ( arrowColorHot . IsEmpty ) arrowColorHot = PluginBase . MainForm . GetThemeColor ( "ScrollBar.HotArrowColor" , arrowColor ) ;
83
+ if ( arrowColorPressed . IsEmpty ) arrowColorPressed = PluginBase . MainForm . GetThemeColor ( "ScrollBar.ActiveArrowColor" , foreColorPressed ) ;
97
84
98
85
colorsInvalidated = false ;
99
86
}
@@ -117,6 +104,7 @@ private void ResetColors()
117
104
backColor =
118
105
backColorDisabled =
119
106
Color . Empty ;
107
+
120
108
colorsInvalidated = true ;
121
109
}
122
110
@@ -128,21 +116,18 @@ private void ResetColors()
128
116
/// <param name="orientation">The <see cref="ScrollBarOrientation"/>.</param>
129
117
private void DrawBackground ( Graphics g , Rectangle rect , ScrollBarOrientation orientation )
130
118
{
131
- if ( g == null )
132
- {
133
- throw new ArgumentNullException ( "g" ) ;
134
- }
119
+ if ( g == null ) throw new ArgumentNullException ( "g" ) ;
120
+
135
121
if ( rect . IsEmpty || g . IsVisibleClipEmpty || ! g . VisibleClipBounds . IntersectsWith ( rect ) )
136
- {
137
122
return ;
138
- }
139
- if ( orientation == ScrollBarOrientation . Vertical )
140
- {
141
- DrawBackgroundVertical ( g , rect ) ;
142
- }
143
- else
144
- {
145
- DrawBackgroundHorizontal ( g , rect ) ;
123
+
124
+ switch ( orientation ) {
125
+ case ScrollBarOrientation . Vertical :
126
+ DrawBackgroundVertical ( g , rect ) ;
127
+ break ;
128
+ default :
129
+ DrawBackgroundHorizontal ( g , rect ) ;
130
+ break ;
146
131
}
147
132
}
148
133
@@ -155,16 +140,12 @@ private void DrawBackground(Graphics g, Rectangle rect, ScrollBarOrientation ori
155
140
/// <param name="orientation">The <see cref="ScrollBarOrientation"/>.</param>
156
141
private void DrawThumb ( Graphics g , Rectangle rect , ScrollBarState state , ScrollBarOrientation orientation )
157
142
{
158
- if ( g == null )
159
- {
160
- throw new ArgumentNullException ( "g" ) ;
161
- }
143
+ if ( g == null ) throw new ArgumentNullException ( "g" ) ;
144
+
162
145
if ( rect . IsEmpty || g . IsVisibleClipEmpty || ! g . VisibleClipBounds . IntersectsWith ( rect ) || state == ScrollBarState . Disabled )
163
- {
164
146
return ;
165
- }
166
147
167
- Color color = foreColor ;
148
+ Color color ;
168
149
switch ( state )
169
150
{
170
151
case ScrollBarState . Hot :
@@ -173,15 +154,18 @@ private void DrawThumb(Graphics g, Rectangle rect, ScrollBarState state, ScrollB
173
154
case ScrollBarState . Pressed :
174
155
color = foreColorPressed ;
175
156
break ;
157
+ default :
158
+ color = foreColor ;
159
+ break ;
176
160
}
177
161
178
- if ( orientation == ScrollBarOrientation . Vertical )
179
- {
180
- DrawThumbVertical ( g , rect , color ) ;
181
- }
182
- else
183
- {
184
- DrawThumbHorizontal ( g , rect , color ) ;
162
+ switch ( orientation ) {
163
+ case ScrollBarOrientation . Vertical :
164
+ DrawThumbVertical ( g , rect , color ) ;
165
+ break ;
166
+ default :
167
+ DrawThumbHorizontal ( g , rect , color ) ;
168
+ break ;
185
169
}
186
170
}
187
171
@@ -195,16 +179,12 @@ private void DrawThumb(Graphics g, Rectangle rect, ScrollBarState state, ScrollB
195
179
/// <param name="orientation">The <see cref="ScrollBarOrientation"/>.</param>
196
180
private void DrawArrowButton ( Graphics g , Rectangle rect , ScrollBarArrowButtonState state , bool arrowUp , ScrollBarOrientation orientation )
197
181
{
198
- if ( g == null )
199
- {
200
- throw new ArgumentNullException ( "g" ) ;
201
- }
182
+ if ( g == null ) throw new ArgumentNullException ( "g" ) ;
183
+
202
184
if ( rect . IsEmpty || g . IsVisibleClipEmpty || ! g . VisibleClipBounds . IntersectsWith ( rect ) )
203
- {
204
185
return ;
205
- }
206
186
207
- Color color = arrowColor ;
187
+ Color color ;
208
188
209
189
switch ( state )
210
190
{
@@ -216,15 +196,18 @@ private void DrawArrowButton(Graphics g, Rectangle rect, ScrollBarArrowButtonSta
216
196
case ScrollBarArrowButtonState . DownPressed :
217
197
color = arrowColorPressed ;
218
198
break ;
199
+ default :
200
+ color = arrowColor ;
201
+ break ;
219
202
}
220
203
221
- if ( orientation == ScrollBarOrientation . Vertical )
222
- {
223
- DrawArrowButtonVertical ( g , rect , color , arrowUp ) ;
224
- }
225
- else
226
- {
227
- DrawArrowButtonHorizontal ( g , rect , color , arrowUp ) ;
204
+ switch ( orientation ) {
205
+ case ScrollBarOrientation . Vertical :
206
+ DrawArrowButtonVertical ( g , rect , color , arrowUp ) ;
207
+ break ;
208
+ default :
209
+ DrawArrowButtonHorizontal ( g , rect , color , arrowUp ) ;
210
+ break ;
228
211
}
229
212
}
230
213
@@ -235,7 +218,7 @@ private void DrawArrowButton(Graphics g, Rectangle rect, ScrollBarArrowButtonSta
235
218
/// <param name="rect">The rectangle in which to paint.</param>
236
219
private void DrawBackgroundVertical ( Graphics g , Rectangle rect )
237
220
{
238
- using ( SolidBrush brush = new SolidBrush ( this . Enabled ? backColor : backColorDisabled ) )
221
+ using ( Brush brush = new SolidBrush ( this . Enabled ? backColor : backColorDisabled ) )
239
222
{
240
223
g . FillRectangle ( brush , rect ) ;
241
224
}
@@ -248,7 +231,7 @@ private void DrawBackgroundVertical(Graphics g, Rectangle rect)
248
231
/// <param name="rect">The rectangle in which to paint.</param>
249
232
private void DrawBackgroundHorizontal ( Graphics g , Rectangle rect )
250
233
{
251
- using ( SolidBrush brush = new SolidBrush ( this . Enabled ? backColor : backColorDisabled ) )
234
+ using ( Brush brush = new SolidBrush ( this . Enabled ? backColor : backColorDisabled ) )
252
235
{
253
236
g . FillRectangle ( brush , rect ) ;
254
237
}
@@ -262,10 +245,11 @@ private void DrawBackgroundHorizontal(Graphics g, Rectangle rect)
262
245
/// <param name="color">The color to draw the thumb with.</param>
263
246
private static void DrawThumbVertical ( Graphics g , Rectangle rect , Color color )
264
247
{
265
- var innerRect = new Rectangle ( rect . Left + ScaleHelper . Scale ( 2 ) , rect . Top , rect . Width - ScaleHelper . Scale ( 4 ) , rect . Height ) ;
248
+ rect . X += ScaleHelper . Scale ( 2 ) ;
249
+ rect . Width -= ScaleHelper . Scale ( 4 ) ;
266
250
using ( Brush brush = new SolidBrush ( color ) )
267
251
{
268
- g . FillRectangle ( brush , innerRect ) ;
252
+ g . FillRectangle ( brush , rect ) ;
269
253
}
270
254
}
271
255
@@ -277,10 +261,11 @@ private static void DrawThumbVertical(Graphics g, Rectangle rect, Color color)
277
261
/// <param name="color">The color to draw the thumb with.</param>
278
262
private static void DrawThumbHorizontal ( Graphics g , Rectangle rect , Color color )
279
263
{
280
- var innerRect = new Rectangle ( rect . Left , rect . Top + ScaleHelper . Scale ( 2 ) , rect . Width , rect . Height - ScaleHelper . Scale ( 4 ) ) ;
264
+ rect . Y += ScaleHelper . Scale ( 2 ) ;
265
+ rect . Height -= ScaleHelper . Scale ( 4 ) ;
281
266
using ( Brush brush = new SolidBrush ( color ) )
282
267
{
283
- g . FillRectangle ( brush , innerRect ) ;
268
+ g . FillRectangle ( brush , rect ) ;
284
269
}
285
270
}
286
271
@@ -317,7 +302,7 @@ private static void DrawArrowButtonVertical(Graphics g, Rectangle rect, Color co
317
302
{
318
303
new Point ( middle . X - pad , middle . Y - 1 ) ,
319
304
new Point ( middle . X + pad + 1 , middle . Y - 1 ) ,
320
- new Point ( middle . X , middle . Y + pad )
305
+ new Point ( middle . X , middle . Y + pad )
321
306
} ;
322
307
break ;
323
308
}
@@ -2238,28 +2223,7 @@ public enum ScrollBarOrientation
2238
2223
/// </summary>
2239
2224
Vertical
2240
2225
}
2241
-
2242
- /// <summary>
2243
- /// Enum for scrollbar usage settings.
2244
- /// </summary>
2245
- public enum ScrollBarMode
2246
- {
2247
- /// <summary>
2248
- /// Turn off the usage of <see cref="ScrollBarEx"/> completely.
2249
- /// </summary>
2250
- Off ,
2251
-
2252
- /// <summary>
2253
- /// Use <see cref="ScrollBarEx"/> only when explicit theme is defined for scroll bars.
2254
- /// </summary>
2255
- Auto ,
2256
-
2257
- /// <summary>
2258
- /// Always use <see cref="ScrollBarEx"/> instead of the system scroll bar.
2259
- /// </summary>
2260
- On
2261
- }
2262
-
2226
+
2263
2227
/// <summary>
2264
2228
/// The scrollbar states.
2265
2229
/// </summary>
0 commit comments