-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathColorSlider.cs
More file actions
1968 lines (1706 loc) · 80 KB
/
ColorSlider.cs
File metadata and controls
1968 lines (1706 loc) · 80 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#region License
/* Copyright (c) 2017 Fabrice Lacharme
* This code is inspired from Michal Brylka
* https://www.codeproject.com/Articles/17395/Owner-drawn-trackbar-slider
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#endregion
#region Contact
/*
* Fabrice Lacharme
* Email: [email protected]
*/
#endregion
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace ColorSlider
{
/* Original code from Michal Brylka on Code Project
* see https://www.codeproject.com/Articles/17395/Owner-drawn-trackbar-slider
* ColorSlider is a trackbar control written in C# as a replacement of the trackbar
*
* CodeProject: https://www.codeproject.com/Tips/1193311/Csharp-Slider-Trackbar-Control-using-Windows-Forms
* Github: https://github.com/fabricelacharme/ColorSlider
*
* 20/11/17 - version 1.0.0.1
*
* Fixed: erroneous vertical display in case of minimum <> 0 (negative or positive)
* Modified: DrawColorSlider, OnMouseMove
*
* Added: Ticks display transformations
* - TickAdd: allow to add a fixed value to the graduations:
* usage: transform K = °C + 273,15, or °F = 1,8°C + 32 K = (°F + 459,67) / 1,8
* - TickDivide: allow to divide by a fixed value the graduations
* usage: divide by 1000 => display graduations in kilograms when in gram
*
*
* 10/12/17 - version 1.0.0.2
* Added ForeColor property to graduations text color
*
* 29/11/2019 - Version 1.0.0.3
* Scale accept decimal negative values (-0.5 to 5.5 for ex)
*
* 20/10/2024 - Version 1.0.0.6
* Slidebar thickness can be modified
*
* 16/12/2024 - Version 1.0.0.7
* ScaleSubDivisions property counts intervals, not tick marks
*
*/
/// <summary>
/// Encapsulates control that visually displays certain integer value and allows user to change it within desired range. It imitates <see cref="System.Windows.Forms.TrackBar"/> as far as mouse usage is concerned.
/// </summary>
[ToolboxBitmap(typeof(TrackBar))]
[DefaultEvent("Scroll"), DefaultProperty("BarInnerColor")]
public partial class ColorSlider : Control
{
#region Events
/// <summary>
/// Fires when Slider position has changed
/// </summary>
[Description("Event fires when the Value property changes")]
[Category("Action")]
public event EventHandler ValueChanged;
/// <summary>
/// Fires when user scrolls the Slider
/// </summary>
[Description("Event fires when the Slider position is changed")]
[Category("Behavior")]
public event ScrollEventHandler Scroll;
#endregion
#region Properties
private Rectangle barRect; //bounding rectangle of bar area
private Rectangle barHalfRect;
private Rectangle thumbHalfRect;
private Rectangle elapsedRect; //bounding rectangle of elapsed area
// Margin left & right (bottom & Top)
private int OffsetL = 0;
private int OffsetR = 0;
#region thumb
private Rectangle thumbRect; //bounding rectangle of thumb area
/// <summary>
/// Gets the thumb rect. Usefull to determine bounding rectangle when creating custom thumb shape.
/// </summary>
/// <value>The thumb rect.</value>
[Browsable(false)]
public Rectangle ThumbRect
{
get { return thumbRect; }
}
private Size _thumbSize = new Size(16, 16);
/// <summary>
/// Gets or sets the size of the thumb.
/// </summary>
/// <value>The size of the thumb.</value>
/// <exception cref="T:System.ArgumentOutOfRangeException">exception thrown when value is lower than zero or greater than half of appropriate dimension</exception>
[Description("Set Slider thumb size")]
[Category("ColorSlider")]
[DefaultValue(typeof(Size), "16, 16")]
public Size ThumbSize
{
get { return _thumbSize; }
set
{
int h = value.Height;
int w = value.Width;
if (h > 0 && w > 0)
{
_thumbSize = new Size(w, h);
}
else
throw new ArgumentOutOfRangeException(
"TrackSize has to be greater than zero and lower than half of Slider width");
Invalidate();
}
}
private GraphicsPath _thumbCustomShape = null;
/// <summary>
/// Gets or sets the thumb custom shape. Use ThumbRect property to determine bounding rectangle.
/// </summary>
/// <value>The thumb custom shape. null means default shape</value>
[Description("Set Slider's thumb's custom shape")]
[Category("ColorSlider")]
[Browsable(false)]
[DefaultValue(typeof(GraphicsPath), "null")]
public GraphicsPath ThumbCustomShape
{
get { return _thumbCustomShape; }
set
{
_thumbCustomShape = value;
//_thumbSize = (int) (_barOrientation == Orientation.Horizontal ? value.GetBounds().Width : value.GetBounds().Height) + 1;
_thumbSize = new Size((int)value.GetBounds().Width, (int)value.GetBounds().Height);
Invalidate();
}
}
private Size _thumbRoundRectSize = new Size(16, 16);
/// <summary>
/// Gets or sets the size of the thumb round rectangle edges.
/// </summary>
/// <value>The size of the thumb round rectangle edges.</value>
[Description("Set Slider's thumb round rect size")]
[Category("ColorSlider")]
[DefaultValue(typeof(Size), "16, 16")]
public Size ThumbRoundRectSize
{
get { return _thumbRoundRectSize; }
set
{
int h = value.Height, w = value.Width;
if (h <= 0) h = 1;
if (w <= 0) w = 1;
_thumbRoundRectSize = new Size(w, h);
Invalidate();
}
}
private Size _borderRoundRectSize = new Size(8, 8);
/// <summary>
/// Gets or sets the size of the border round rect.
/// </summary>
/// <value>The size of the border round rect.</value>
[Description("Set Slider's border round rect size")]
[Category("ColorSlider")]
[DefaultValue(typeof(Size), "8, 8")]
public Size BorderRoundRectSize
{
get { return _borderRoundRectSize; }
set
{
int h = value.Height, w = value.Width;
if (h <= 0) h = 1;
if (w <= 0) w = 1;
_borderRoundRectSize = new Size(w, h);
Invalidate();
}
}
private bool _drawSemitransparentThumb = true;
/// <summary>
/// Gets or sets a value indicating whether to draw semitransparent thumb.
/// </summary>
/// <value><c>true</c> if semitransparent thumb should be drawn; otherwise, <c>false</c>.</value>
[Description("Set whether to draw semitransparent thumb")]
[Category("ColorSlider")]
[DefaultValue(true)]
public bool DrawSemitransparentThumb
{
get { return _drawSemitransparentThumb; }
set
{
_drawSemitransparentThumb = value;
Invalidate();
}
}
private Image _thumbImage = null;
//private Image _thumbImage = Properties.Resources.BTN_Thumb_Blue;
/// <summary>
/// Gets or sets the Image used to render the thumb.
/// </summary>
/// <value>the thumb Image</value>
[Description("Set to use a specific Image for the thumb")]
[Category("ColorSlider")]
[DefaultValue(null)]
public Image ThumbImage
{
get { return _thumbImage; }
set
{
if (value != null)
_thumbImage = value;
else
_thumbImage = null;
Invalidate();
}
}
#endregion
#region Appearance
private float _barthickness = 1f;//2.5f;
/// <summary>
/// Gets or sets the thickness of the slider (default 1)
/// </summary>
[Description("Set Slider Thickness")]
[DefaultValue(1f)]
public float BarThickness
{
get { return _barthickness; }
set
{
if (value >= 1)
{
_barthickness = value;
Invalidate();
}
}
}
private int _padding = 0;
/// <summary>
/// Gets or sets the padding (inside margins: left & right or bottom & top)
/// </summary>
/// <value>The padding.</value>
[Description("Set Slider padding (inside margins: left & right or bottom & top)")]
[Category("ColorSlider")]
[DefaultValue(0)]
public new int Padding
{
get { return _padding; }
set
{
if (_padding != value)
{
_padding = value;
OffsetL = OffsetR = _padding;
Invalidate();
}
}
}
private Orientation _barOrientation = Orientation.Horizontal;
/// <summary>
/// Gets or sets the orientation of Slider.
/// </summary>
/// <value>The orientation.</value>
[Description("Set Slider orientation")]
[Category("ColorSlider")]
[DefaultValue(Orientation.Horizontal)]
public Orientation Orientation
{
get { return _barOrientation; }
set
{
if (_barOrientation != value)
{
_barOrientation = value;
// Switch from horizontal to vertical (design mode)
// Comment these lines if problems in Run mode
if (this.DesignMode)
{
int temp = Width;
Width = Height;
Height = temp;
}
Invalidate();
}
}
}
private bool _drawFocusRectangle = false;
/// <summary>
/// Gets or sets a value indicating whether to draw focus rectangle.
/// </summary>
/// <value><c>true</c> if focus rectangle should be drawn; otherwise, <c>false</c>.</value>
[Description("Set whether to draw focus rectangle")]
[Category("ColorSlider")]
[DefaultValue(false)]
public bool DrawFocusRectangle
{
get { return _drawFocusRectangle; }
set
{
_drawFocusRectangle = value;
Invalidate();
}
}
private bool _mouseEffects = true;
/// <summary>
/// Gets or sets whether mouse entry and exit actions have impact on how control look.
/// </summary>
/// <value><c>true</c> if mouse entry and exit actions have impact on how control look; otherwise, <c>false</c>.</value>
[Description("Set whether mouse entry and exit actions have impact on how control look")]
[Category("ColorSlider")]
[DefaultValue(true)]
public bool MouseEffects
{
get { return _mouseEffects; }
set
{
_mouseEffects = value;
Invalidate();
}
}
#endregion
#region values
private decimal _trackerValue = 30;
/// <summary>
/// Gets or sets the value of Slider.
/// </summary>
/// <value>The value.</value>
/// <exception cref="T:System.ArgumentOutOfRangeException">exception thrown when value is outside appropriate range (min, max)</exception>
[Description("Set Slider value")]
[Category("ColorSlider")]
[DefaultValue(typeof(decimal), "30")]
public decimal Value
{
get { return _trackerValue; }
set
{
if (value >= _minimum & value <= _maximum)
{
_trackerValue = value;
if (ValueChanged != null) ValueChanged(this, new EventArgs());
Invalidate();
}
else throw new ArgumentOutOfRangeException("Value is outside appropriate range (min, max)");
}
}
private decimal _minimum = 0;
/// <summary>
/// Gets or sets the minimum value.
/// </summary>
/// <value>The minimum value.</value>
[Description("Set Slider minimal point")]
[Category("ColorSlider")]
[DefaultValue(typeof(decimal), "0")]
public decimal Minimum
{
get { return _minimum; }
set
{
_minimum = value;
if (_maximum < value)
_maximum = value;
if (Value < value)
Value = value;
Invalidate();
}
}
private decimal _maximum = 100;
/// <summary>
/// Gets or sets the maximum value.
/// </summary>
/// <value>The maximum value.</value>
[Description("Set Slider maximal point")]
[Category("ColorSlider")]
[DefaultValue(typeof(decimal), "100")]
public decimal Maximum
{
get { return _maximum; }
set
{
_maximum = value;
if (_minimum > value)
_minimum = value;
if (Value > value)
Value = value;
Invalidate();
}
}
private decimal _smallChange = 1;
/// <summary>
/// Gets or sets trackbar's small change. It affects how to behave when directional keys are pressed
/// </summary>
/// <value>The small change value.</value>
[Description("Set trackbar's small change")]
[Category("ColorSlider")]
[DefaultValue(typeof(decimal), "1")]
public decimal SmallChange
{
get { return _smallChange; }
set { _smallChange = value; }
}
private decimal _largeChange = 5;
/// <summary>
/// Gets or sets trackbar's large change. It affects how to behave when PageUp/PageDown keys are pressed
/// </summary>
/// <value>The large change value.</value>
[Description("Set trackbar's large change")]
[Category("ColorSlider")]
[DefaultValue(typeof(decimal), "5")]
public decimal LargeChange
{
get { return _largeChange; }
set { _largeChange = value; }
}
private int _mouseWheelBarPartitions = 10;
/// <summary>
/// Gets or sets the mouse wheel bar partitions.
/// </summary>
/// <value>The mouse wheel bar partitions.</value>
/// <exception cref="T:System.ArgumentOutOfRangeException">exception thrown when value isn't greater than zero</exception>
[Description("Set to how many parts is bar divided when using mouse wheel")]
[Category("ColorSlider")]
[DefaultValue(10)]
public int MouseWheelBarPartitions
{
get { return _mouseWheelBarPartitions; }
set
{
if (value > 0)
_mouseWheelBarPartitions = value;
else throw new ArgumentOutOfRangeException("MouseWheelBarPartitions has to be greater than zero");
}
}
#endregion
#region colors
private Color _thumbOuterColor = Color.White;
/// <summary>
/// Gets or sets the thumb outer color.
/// </summary>
/// <value>The thumb outer color.</value>
[Description("Sets Slider thumb outer color")]
[Category("ColorSlider")]
[DefaultValue(typeof(Color), "White")]
public Color ThumbOuterColor
{
get { return _thumbOuterColor; }
set
{
_thumbOuterColor = value;
Invalidate();
}
}
private Color _thumbInnerColor = Color.FromArgb(21, 56, 152);
/// <summary>
/// Gets or sets the inner color of the thumb.
/// </summary>
/// <value>The inner color of the thumb.</value>
[Description("Set Slider thumb inner color")]
[Category("ColorSlider")]
[DefaultValue(typeof(Color), "21, 56, 152")]
public Color ThumbInnerColor
{
get { return _thumbInnerColor; }
set
{
_thumbInnerColor = value;
Invalidate();
}
}
private Color _thumbPenColor = Color.FromArgb(21, 56, 152);
/// <summary>
/// Gets or sets the color of the thumb pen.
/// </summary>
/// <value>The color of the thumb pen.</value>
[Description("Set Slider thumb pen color")]
[Category("ColorSlider")]
[DefaultValue(typeof(Color), "21, 56, 152")]
public Color ThumbPenColor
{
get { return _thumbPenColor; }
set
{
_thumbPenColor = value;
Invalidate();
}
}
private Color _barInnerColor = Color.Black;
/// <summary>
/// Gets or sets the inner color of the bar.
/// </summary>
/// <value>The inner color of the bar.</value>
[Description("Set Slider bar inner color")]
[Category("ColorSlider")]
[DefaultValue(typeof(Color), "Black")]
public Color BarInnerColor
{
get { return _barInnerColor; }
set
{
_barInnerColor = value;
Invalidate();
}
}
private Color _elapsedPenColorTop = Color.FromArgb(95, 140, 180); // bleu clair
/// <summary>
/// Gets or sets the top color of the Elapsed
/// </summary>
[Description("Gets or sets the top color of the elapsed")]
[Category("ColorSlider")]
[DefaultValue(typeof(Color), "95, 140, 180")]
public Color ElapsedPenColorTop
{
get { return _elapsedPenColorTop; }
set
{
_elapsedPenColorTop = value;
Invalidate();
}
}
private Color _elapsedPenColorBottom = Color.FromArgb(99, 130, 208); // bleu très clair
/// <summary>
/// Gets or sets the bottom color of the elapsed
/// </summary>
[Description("Gets or sets the bottom color of the elapsed")]
[Category("ColorSlider")]
[DefaultValue(typeof(Color), "99, 130, 208")]
public Color ElapsedPenColorBottom
{
get { return _elapsedPenColorBottom; }
set
{
_elapsedPenColorBottom = value;
Invalidate();
}
}
private Color _barPenColorTop = Color.FromArgb(55, 60, 74); // gris foncé
/// <summary>
/// Gets or sets the top color of the bar
/// </summary>
[Description("Gets or sets the top color of the bar")]
[Category("ColorSlider")]
[DefaultValue(typeof(Color), "55, 60, 74")]
public Color BarPenColorTop
{
get { return _barPenColorTop; }
set
{
_barPenColorTop = value;
Invalidate();
}
}
private Color _barPenColorBottom = Color.FromArgb(87, 94, 110); // gris moyen
/// <summary>
/// Gets or sets the bottom color of bar
/// </summary>
[Description("Gets or sets the bottom color of the bar")]
[Category("ColorSlider")]
[DefaultValue(typeof(Color), "87, 94, 110")]
public Color BarPenColorBottom
{
get { return _barPenColorBottom; }
set
{
_barPenColorBottom = value;
Invalidate();
}
}
private Color _elapsedInnerColor = Color.FromArgb(21, 56, 152);
/// <summary>
/// Gets or sets the inner color of the elapsed.
/// </summary>
/// <value>The inner color of the elapsed.</value>
[Description("Set Slider's elapsed part inner color")]
[Category("ColorSlider")]
[DefaultValue(typeof(Color), "21, 56, 152")]
public Color ElapsedInnerColor
{
get { return _elapsedInnerColor; }
set
{
_elapsedInnerColor = value;
Invalidate();
}
}
private Color _tickColor = Color.White;
/// <summary>
/// Gets or sets the color of the graduations
/// </summary>
[Description("Color of graduations")]
[Category("ColorSlider")]
[DefaultValue(typeof(Color), "White")]
public Color TickColor
{
get { return _tickColor; }
set
{
if (value != _tickColor)
{
_tickColor = value;
Invalidate();
}
}
}
#endregion
#region divisions
// For ex: if values are multiples of 50,
// values = 0, 50, 100, 150 etc...
//set TickDivide to 50
// And ticks will be displayed as
// values = 0, 1, 2, 3 etc...
private float _tickDivide = 0;
[Description("Gets or sets a value used to divide the graduation")]
[Category("ColorSlider")]
[DefaultValue(0f)]
public float TickDivide
{
get { return _tickDivide; }
set {
_tickDivide = value;
Invalidate();
}
}
private float _tickAdd = 0;
[Description("Gets or sets a value added to the graduation")]
[Category("ColorSlider")]
[DefaultValue(0f)]
public float TickAdd
{
get { return _tickAdd; }
set { _tickAdd = value;
Invalidate();
}
}
private TickStyle _tickStyle = TickStyle.TopLeft;
/// <summary>
/// Gets or sets where to display the ticks (None, both top-left, bottom-right)
/// </summary>
[Description("Gets or sets where to display the ticks")]
[Category("ColorSlider")]
[DefaultValue(TickStyle.TopLeft)]
public TickStyle TickStyle
{
get { return _tickStyle; }
set {
_tickStyle = value;
Invalidate();
}
}
private int _scaleDivisions = 10;
/// <summary>
/// How many divisions of maximum?
/// </summary>
[Description("Set the number of intervals between minimum and maximum")]
[Category("ColorSlider")]
[DefaultValue(10)]
public int ScaleDivisions
{
get { return _scaleDivisions; }
set
{
if (value > 0)
{
_scaleDivisions = value;
Invalidate();
}
//else throw new ArgumentOutOfRangeException("TickFreqency must be > 0 and < Maximum");
}
}
private int _scaleSubDivisions = 5;
/// <summary>
/// How many subdivisions for each division
/// </summary>
[Description("Set the number of subdivisions between main divisions of graduation.")]
[Category("ColorSlider")]
[DefaultValue(5)]
public int ScaleSubDivisions
{
get { return _scaleSubDivisions; }
set
{
if (value > 0)
{
_scaleSubDivisions = value;
Invalidate();
}
//else throw new ArgumentOutOfRangeException("TickSubFreqency must be > 0 and < TickFrequency");
}
}
private bool _showSmallScale = false;
/// <summary>
/// Shows Small Scale marking.
/// </summary>
[Description("Show or hide subdivisions of graduations")]
[Category("ColorSlider")]
[DefaultValue(false)]
public bool ShowSmallScale
{
get { return _showSmallScale; }
set {
_showSmallScale = value;
Invalidate();
}
}
private bool _showDivisionsText = true;
/// <summary>
/// Show or hide text value of graduations.
/// </summary>
[Description("Show or hide text value of graduations")]
[Category("ColorSlider")]
[DefaultValue(true)]
public bool ShowDivisionsText
{
get { return _showDivisionsText; }
set { _showDivisionsText = value;
Invalidate();
}
}
#endregion
#region Font
/// <summary>
/// Get or Sets the Font of the Text being displayed.
/// </summary>
[Bindable(true),
Browsable(true),
Category("ColorSlider"),
Description("Get or Sets the Font of the Text being displayed."),
DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
EditorBrowsable(EditorBrowsableState.Always),
DefaultValue(typeof(Font), "Microsoft Sans Serif, 6pt")]
public override Font Font
{
get
{
return base.Font;
}
set
{
base.Font = value;
Invalidate();
OnFontChanged(EventArgs.Empty);
}
}
/// <summary>
/// Get or Sets the Color of the Text being displayed.
/// </summary>
[Bindable(true),
Browsable(true),
Category("ColorSlider"),
Description("Get or Sets the Color of the Text being displayed."),
DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
EditorBrowsable(EditorBrowsableState.Always),
DefaultValue(typeof(Color), "White")]
public override Color ForeColor {
get
{
return base.ForeColor;
}
set
{
base.ForeColor = value;
Invalidate();
OnForeColorChanged(EventArgs.Empty);
}
}
#endregion
#endregion
#region Color schemas
//define own color schemas
private Color[,] aColorSchema = new Color[,]
{
{
Color.White, // thumb outer
Color.FromArgb(21, 56, 152), // thumb inner
Color.FromArgb(21, 56, 152), // thumb pen color
Color.Black, // bar inner
Color.FromArgb(95, 140, 180), // slider elapsed top
Color.FromArgb(99, 130, 208), // slider elapsed bottom
Color.FromArgb(55, 60, 74), // slider remain top
Color.FromArgb(87, 94, 110), // slider remain bottom
Color.FromArgb(21, 56, 152) // elapsed interieur centre
},
{
Color.White, // thumb outer
Color.Red, // thumb inner
Color.Red, // thumb pen color
Color.Black, // bar inner
Color.LightCoral, // slider elapsed top
Color.Salmon, // slider elapsed bottom
Color.FromArgb(55, 60, 74), // slider remain top
Color.FromArgb(87, 94, 110), // slider remain bottom
Color.Red // gauche interieur centre
},
{
Color.White, // thumb outer
Color.Green, // thumb inner
Color.Green, // thumb pen color
Color.Black, // bar inner
Color.SpringGreen, // slider elapsed top
Color.LightGreen, // slider elapsed bottom
Color.FromArgb(55, 60, 74), // slider remain top
Color.FromArgb(87, 94, 110), // slider remain bottom
Color.Green // gauche interieur centre
},
};
public enum ColorSchemas
{
BlueColors,
RedColors,
GreenColors
}
private ColorSchemas colorSchema = ColorSchemas.BlueColors;
/// <summary>
/// Sets color schema. Color generalization / fast color changing. Has no effect when slider colors are changed manually after schema was applied.
/// </summary>
/// <value>New color schema value</value>
[Description("Set Slider color schema. Has no effect when slider colors are changed manually after schema was applied.")]
[Category("ColorSlider")]
[DefaultValue(typeof(ColorSchemas), "BlueColors")]
public ColorSchemas ColorSchema
{
get { return colorSchema; }
set
{
colorSchema = value;
byte sn = (byte)value;
_thumbOuterColor = aColorSchema[sn, 0];
_thumbInnerColor = aColorSchema[sn, 1];
_thumbPenColor = aColorSchema[sn, 2];
_barInnerColor = aColorSchema[sn, 3];
_elapsedPenColorTop = aColorSchema[sn, 4];
_elapsedPenColorBottom = aColorSchema[sn, 5];
_barPenColorTop = aColorSchema[sn, 6];
_barPenColorBottom = aColorSchema[sn, 7];
_elapsedInnerColor = aColorSchema[sn, 8];
Invalidate();
}
}
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="ColorSlider"/> class.
/// </summary>
/// <param name="min">The minimum value.</param>
/// <param name="max">The maximum value.</param>
/// <param name="value">The current value.</param>
public ColorSlider(decimal min, decimal max, decimal value)
{
InitializeComponent();
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer |
ControlStyles.ResizeRedraw | ControlStyles.Selectable |
ControlStyles.SupportsTransparentBackColor | ControlStyles.UserMouse |
ControlStyles.UserPaint, true);
// Default backcolor
BackColor = Color.FromArgb(70, 77, 95);
ForeColor = Color.White;
// Font
//this.Font = new Font("Tahoma", 6.75f);
this.Font = new Font("Microsoft Sans Serif", 6f);
Minimum = min;
Maximum = max;
Value = value;
}
/// <summary>
/// Initializes a new instance of the <see cref="ColorSlider"/> class.
/// </summary>
public ColorSlider() : this(0, 100, 30) { }
#endregion