forked from utPLSQL/utPLSQL-PLSQL-Developer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColorProgressBar.cs
More file actions
235 lines (205 loc) · 6.26 KB
/
ColorProgressBar.cs
File metadata and controls
235 lines (205 loc) · 6.26 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
using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing;
namespace ColorProgressBar
{
[Description("Color Progress Bar")]
[ToolboxBitmap(typeof(ProgressBar))]
[Designer(typeof(ColorProgressBarDesigner))]
public class ColorProgressBar : System.Windows.Forms.Control
{
private int _Value = 0;
private int _Minimum = 0;
private int _Maximum = 100;
private int _Step = 10;
private Color _BarColor = Color.Green;
private Color _BorderColor = Color.Black;
public ColorProgressBar()
{
base.Size = new Size(200, 20);
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.DoubleBuffer, true);
}
[Description("Progress bar color")]
[Category("ColorProgressBar")]
public Color BarColor
{
get
{
return _BarColor;
}
set
{
_BarColor = value;
this.Invalidate();
}
}
[Description("The current value for the progres bar. Must be between Minimum and Maximum.")]
[Category("ColorProgressBar")]
[RefreshProperties(RefreshProperties.All)]
public int Value
{
get
{
return _Value;
}
set
{
if (value < _Minimum)
{
throw new ArgumentException($"'{value}' is not a valid 'Value'.\n'Value' must be between 'Minimum' and 'Maximum'.");
}
if (value > _Maximum)
{
throw new ArgumentException($"'{value}' is not a valid 'Value'.\n'Value' must be between 'Minimum' and 'Maximum'.");
}
_Value = value;
this.Invalidate();
}
}
[Description("The lower bound of the range.")]
[Category("ColorProgressBar")]
[RefreshProperties(RefreshProperties.All)]
public int Minimum
{
get
{
return _Minimum;
}
set
{
_Minimum = value;
if (_Minimum > _Maximum)
_Maximum = _Minimum;
if (_Minimum > _Value)
_Value = _Minimum;
this.Invalidate();
}
}
[Description("The uppper bound of the range.")]
[Category("ColorProgressBar")]
[RefreshProperties(RefreshProperties.All)]
public int Maximum
{
get
{
return _Maximum;
}
set
{
_Maximum = value;
if (_Maximum < _Value)
_Value = _Maximum;
if (_Maximum < _Minimum)
_Minimum = _Maximum;
this.Invalidate();
}
}
[Description("The value to move the progess bar when the Step() method is called.")]
[Category("ColorProgressBar")]
public int Step
{
get
{
return _Step;
}
set
{
_Step = value;
this.Invalidate();
}
}
[Description("The border color")]
[Category("ColorProgressBar")]
public Color BorderColor
{
get
{
return _BorderColor;
}
set
{
_BorderColor = value;
this.Invalidate();
}
}
///
/// <summary>Call the PerformStep() method to increase the value displayed by the value set in the Step property</summary>
///
public void PerformStep()
{
if (_Value < _Maximum)
_Value += _Step;
else
_Value = _Maximum;
this.Invalidate();
}
///
/// <summary>Call the PerformStepBack() method to decrease the value displayed by the value set in the Step property</summary>
///
public void PerformStepBack()
{
if (_Value > _Minimum)
_Value -= _Step;
else
_Value = _Minimum;
this.Invalidate();
}
///
/// <summary>Call the Increment() method to increase the value displayed by the passed value</summary>
///
public void Increment(int value)
{
if (_Value < _Maximum)
_Value += value;
else
_Value = _Maximum;
this.Invalidate();
}
//
// <summary>Call the Decrement() method to decrease the value displayed by the passed value</summary>
//
public void Decrement(int value)
{
if (_Value > _Minimum)
_Value -= value;
else
_Value = _Minimum;
this.Invalidate();
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
//
// Check for value
//
if (_Maximum == _Minimum || _Value == 0)
{
// Draw border only and exit;
DrawBorder(e.Graphics);
return;
}
//
// The following is the width of the bar. This will vary with each value.
//
int fillWidth = (this.Width * _Value) / (_Maximum - _Minimum);
//
// Rectangles for upper and lower half of bar
//
Rectangle rect = new Rectangle(0, 0, fillWidth, this.Height);
//
// The brush
//
SolidBrush brush = new SolidBrush(_BarColor);
e.Graphics.FillRectangle(brush, rect);
brush.Dispose();
//
// Draw border and exit
DrawBorder(e.Graphics);
}
protected void DrawBorder(Graphics g)
{
Rectangle borderRect = new Rectangle(0, 0, ClientRectangle.Width - 1, ClientRectangle.Height - 1);
g.DrawRectangle(new Pen(_BorderColor, 1), borderRect);
}
}
}