@@ -32,7 +32,7 @@ public class ScrollBarEx : Control
32
32
private Color backColor /* = SystemColors.ActiveBorder*/ ;
33
33
private Color backColorDisabled /* = SystemColors.ControlLight*/ ;
34
34
35
- private bool colorsValidated ;
35
+ private bool colorsInvalidated ;
36
36
37
37
/// <summary>
38
38
/// Resets the component colors to default values.
@@ -50,18 +50,21 @@ private void InitializeColors()
50
50
arrowColorPressed = SystemColors . HotTrack ;
51
51
backColor = SystemColors . Control ;
52
52
backColorDisabled = SystemColors . ControlLight ;
53
- colorsValidated = true ;
53
+ colorsInvalidated = false ;
54
54
Invalidate ( ) ;
55
55
}
56
56
57
57
/// <summary>
58
- /// Validates any unassigned colors to either default to associated colors.
58
+ /// Validates any unassigned colors to either default or to associated colors.
59
59
/// Calling this method without assigning any new colors will set all colors to default.
60
+ /// <para/>
61
+ /// Call this method after the theme has been changed.
60
62
/// </summary>
61
63
public void ValidateColors ( )
62
64
{
63
- if ( colorsValidated )
65
+ if ( ! colorsInvalidated )
64
66
{
67
+ // No colors defined explicitly -> Reset colors to default.
65
68
InitializeColors ( ) ;
66
69
return ;
67
70
}
@@ -73,20 +76,22 @@ public void ValidateColors()
73
76
if ( foreColorPressed . IsEmpty ) foreColorPressed = SystemColors . ControlDarkDark ;
74
77
if ( backColor . IsEmpty ) backColor = SystemColors . Control ;
75
78
if ( backColorDisabled . IsEmpty ) backColorDisabled = SystemColors . ControlLight ;
76
- // new colors
79
+ // Newly introduced color options - do not assign default colors. Instead fall back to associated colors
77
80
if ( foreColorHot . IsEmpty ) foreColorHot = foreColor ;
78
81
if ( arrowColor . IsEmpty ) arrowColor = foreColor ;
79
82
if ( arrowColorHot . IsEmpty ) arrowColorHot = foreColorHot ;
80
83
if ( arrowColorPressed . IsEmpty ) arrowColorPressed = foreColorPressed ;
81
84
82
- colorsValidated = true ;
85
+ colorsInvalidated = false ;
83
86
}
84
87
85
88
/// <summary>
86
- /// Resets all colors to null values.
89
+ /// Resets all validated colors to null values. Call this method before setting new colors .
87
90
/// </summary>
88
91
private void ResetColors ( )
89
92
{
93
+ if ( colorsInvalidated ) return ;
94
+
90
95
curPosColor =
91
96
borderColor =
92
97
borderColorDisabled =
@@ -99,7 +104,7 @@ private void ResetColors()
99
104
backColor =
100
105
backColorDisabled =
101
106
Color . Empty ;
102
- colorsValidated = false ;
107
+ colorsInvalidated = true ;
103
108
}
104
109
105
110
/// <summary>
@@ -237,11 +242,11 @@ private void DrawBackgroundHorizontal(Graphics g, Rectangle rect)
237
242
}
238
243
239
244
/// <summary>
240
- /// Draws the thumb.
245
+ /// Draws the vertical thumb.
241
246
/// </summary>
242
247
/// <param name="g">The <see cref="Graphics"/> used to paint.</param>
243
248
/// <param name="rect">The rectangle in which to paint.</param>
244
- /// <param name="state ">The <see cref="ScrollBarState"/> of the thumb.</param>
249
+ /// <param name="color ">The color to draw the thumb with .</param>
245
250
private void DrawThumbVertical ( Graphics g , Rectangle rect , Color color )
246
251
{
247
252
var innerRect = new Rectangle ( rect . Left + ScaleHelper . Scale ( 2 ) , rect . Top , rect . Width - ScaleHelper . Scale ( 4 ) , rect . Height ) ;
@@ -253,11 +258,11 @@ private void DrawThumbVertical(Graphics g, Rectangle rect, Color color)
253
258
}
254
259
255
260
/// <summary>
256
- /// Draws the thumb.
261
+ /// Draws the horizontal thumb.
257
262
/// </summary>
258
263
/// <param name="g">The <see cref="Graphics"/> used to paint.</param>
259
264
/// <param name="rect">The rectangle in which to paint.</param>
260
- /// <param name="state ">The <see cref="ScrollBarState"/> of the thumb.</param>
265
+ /// <param name="color ">The color to draw the thumb with .</param>
261
266
private void DrawThumbHorizontal ( Graphics g , Rectangle rect , Color color )
262
267
{
263
268
var innerRect = new Rectangle ( rect . Left , rect . Top + ScaleHelper . Scale ( 2 ) , rect . Width , rect . Height - ScaleHelper . Scale ( 4 ) ) ;
@@ -268,11 +273,11 @@ private void DrawThumbHorizontal(Graphics g, Rectangle rect, Color color)
268
273
}
269
274
270
275
/// <summary>
271
- /// Draws an arrow button .
276
+ /// Draws arrow buttons for vertical scroll bar .
272
277
/// </summary>
273
278
/// <param name="g">The <see cref="Graphics"/> used to paint.</param>
274
279
/// <param name="rect">The rectangle in which to paint.</param>
275
- /// <param name="state ">The <see cref="ScrollBarArrowButtonState"/> of the arrow button .</param>
280
+ /// <param name="color ">The color to draw the arrow buttons with .</param>
276
281
/// <param name="arrowUp">true for an up arrow, false otherwise.</param>
277
282
private void DrawArrowButtonVertical ( Graphics g , Rectangle rect , Color color , bool arrowUp )
278
283
{
@@ -310,11 +315,11 @@ private void DrawArrowButtonVertical(Graphics g, Rectangle rect, Color color, bo
310
315
}
311
316
312
317
/// <summary>
313
- /// Draws an arrow button .
318
+ /// Draws arrow buttons for horizontal scroll bar .
314
319
/// </summary>
315
320
/// <param name="g">The <see cref="Graphics"/> used to paint.</param>
316
321
/// <param name="rect">The rectangle in which to paint.</param>
317
- /// <param name="state ">The <see cref="ScrollBarArrowButtonState"/> of the arrow button .</param>
322
+ /// <param name="color ">The color to draw the arrow buttons with .</param>
318
323
/// <param name="arrowUp">true for an up arrow, false otherwise.</param>
319
324
private void DrawArrowButtonHorizontal ( Graphics g , Rectangle rect , Color color , bool arrowUp )
320
325
{
@@ -886,7 +891,7 @@ public Color BorderColor
886
891
}
887
892
set
888
893
{
889
- if ( colorsValidated ) ResetColors ( ) ;
894
+ ResetColors ( ) ;
890
895
this . borderColor = value ;
891
896
this . Invalidate ( ) ;
892
897
}
@@ -906,7 +911,7 @@ public Color DisabledBorderColor
906
911
}
907
912
set
908
913
{
909
- if ( colorsValidated ) ResetColors ( ) ;
914
+ ResetColors ( ) ;
910
915
this . borderColorDisabled = value ;
911
916
this . Invalidate ( ) ;
912
917
}
@@ -926,7 +931,7 @@ public override Color BackColor
926
931
}
927
932
set
928
933
{
929
- if ( colorsValidated ) ResetColors ( ) ;
934
+ ResetColors ( ) ;
930
935
this . backColor = value ;
931
936
this . Invalidate ( ) ;
932
937
}
@@ -946,7 +951,7 @@ public Color DisabledBackColor
946
951
}
947
952
set
948
953
{
949
- if ( colorsValidated ) ResetColors ( ) ;
954
+ ResetColors ( ) ;
950
955
this . backColorDisabled = value ;
951
956
this . Invalidate ( ) ;
952
957
}
@@ -966,7 +971,7 @@ public override Color ForeColor
966
971
}
967
972
set
968
973
{
969
- if ( colorsValidated ) ResetColors ( ) ;
974
+ ResetColors ( ) ;
970
975
this . foreColor = value ;
971
976
this . Invalidate ( ) ;
972
977
}
@@ -983,7 +988,7 @@ public Color HotForeColor
983
988
get { return this . foreColorHot ; }
984
989
set
985
990
{
986
- if ( colorsValidated ) ResetColors ( ) ;
991
+ ResetColors ( ) ;
987
992
this . foreColorHot = value ;
988
993
this . Invalidate ( ) ;
989
994
}
@@ -1003,7 +1008,7 @@ public Color ActiveForeColor
1003
1008
}
1004
1009
set
1005
1010
{
1006
- if ( colorsValidated ) ResetColors ( ) ;
1011
+ ResetColors ( ) ;
1007
1012
this . foreColorPressed = value ;
1008
1013
this . Invalidate ( ) ;
1009
1014
}
@@ -1020,7 +1025,7 @@ public Color ArrowColor
1020
1025
get { return this . arrowColor ; }
1021
1026
set
1022
1027
{
1023
- if ( colorsValidated ) ResetColors ( ) ;
1028
+ ResetColors ( ) ;
1024
1029
this . arrowColor = value ;
1025
1030
this . Invalidate ( ) ;
1026
1031
}
@@ -1037,7 +1042,7 @@ public Color HotArrowColor
1037
1042
get { return this . arrowColorHot ; }
1038
1043
set
1039
1044
{
1040
- if ( colorsValidated ) ResetColors ( ) ;
1045
+ ResetColors ( ) ;
1041
1046
this . arrowColorHot = value ;
1042
1047
this . Invalidate ( ) ;
1043
1048
}
@@ -1054,7 +1059,7 @@ public Color ActiveArrowColor
1054
1059
get { return this . arrowColorPressed ; }
1055
1060
set
1056
1061
{
1057
- if ( colorsValidated ) ResetColors ( ) ;
1062
+ ResetColors ( ) ;
1058
1063
this . arrowColorPressed = value ;
1059
1064
this . Invalidate ( ) ;
1060
1065
}
@@ -1074,7 +1079,7 @@ public Color CurrentPositionColor
1074
1079
}
1075
1080
set
1076
1081
{
1077
- if ( colorsValidated ) ResetColors ( ) ;
1082
+ ResetColors ( ) ;
1078
1083
this . curPosColor = value ;
1079
1084
this . Invalidate ( ) ;
1080
1085
}
0 commit comments