1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (C) 2004-2005 Novell, Inc.
23 // Jordi Mas i Hernandez jordi@ximian.com
29 using System.ComponentModel;
30 using System.Drawing.Imaging;
31 using System.Drawing.Drawing2D;
33 namespace System.Windows.Forms
35 [DefaultProperty ("Value")]
36 public sealed class ProgressBar : Control
38 #region Local Variables
43 internal Rectangle client_area = new Rectangle ();
44 #endregion // Local Variables
48 [EditorBrowsable (EditorBrowsableState.Never)]
49 public new event EventHandler BackColorChanged;
52 [EditorBrowsable (EditorBrowsableState.Never)]
53 public new event EventHandler BackgroundImageChanged;
56 [EditorBrowsable (EditorBrowsableState.Never)]
57 public new event EventHandler CausesValidationChanged;
60 [EditorBrowsable (EditorBrowsableState.Never)]
61 public new event EventHandler DoubleClick;
64 [EditorBrowsable (EditorBrowsableState.Never)]
65 public new event EventHandler Enter;
68 [EditorBrowsable (EditorBrowsableState.Never)]
69 public new event EventHandler FontChanged;
72 [EditorBrowsable (EditorBrowsableState.Never)]
73 public new event EventHandler ForeColorChanged;
76 [EditorBrowsable (EditorBrowsableState.Never)]
77 public new event EventHandler ImeModeChanged;
80 [EditorBrowsable (EditorBrowsableState.Never)]
81 public new event KeyEventHandler KeyDown;
84 [EditorBrowsable (EditorBrowsableState.Never)]
85 public new event KeyPressEventHandler KeyPress;
88 [EditorBrowsable (EditorBrowsableState.Never)]
89 public new event KeyEventHandler KeyUp;
92 [EditorBrowsable (EditorBrowsableState.Never)]
93 public new event EventHandler Leave;
96 [EditorBrowsable (EditorBrowsableState.Never)]
97 public new event PaintEventHandler Paint;
100 [EditorBrowsable (EditorBrowsableState.Never)]
101 public new event EventHandler RightToLeftChanged;
104 [EditorBrowsable (EditorBrowsableState.Never)]
105 public new event EventHandler TabStopChanged;
108 [EditorBrowsable (EditorBrowsableState.Never)]
109 public new event EventHandler TextChanged;
112 #region Public Constructors
120 base.Paint += new PaintEventHandler (OnPaintPB);
121 base.Resize += new EventHandler (OnResizeTB);
123 SetStyle (ControlStyles.UserPaint |
124 ControlStyles.Selectable |
125 ControlStyles.ResizeRedraw |
126 ControlStyles.Opaque, false);
128 #endregion // Public Constructors
130 #region Public Instance Properties
133 [EditorBrowsable (EditorBrowsableState.Never)]
134 public override bool AllowDrop
136 get { return base.AllowDrop; }
138 base.AllowDrop = value;
142 // Setting this property in MS .Net 1.1 does not have any visual effect and it
143 // does not fire a BackColorChanged event
145 [EditorBrowsable (EditorBrowsableState.Never)]
146 public override Color BackColor
148 get { return base.BackColor; }
149 set { base.BackColor = value; }
152 // Setting this property in MS .Net 1.1 does not have any visual effect and it
153 // does not fire a BackgroundImageChanged event
155 [EditorBrowsable (EditorBrowsableState.Never)]
156 public override Image BackgroundImage
158 get { return base.BackgroundImage; }
159 set { base.BackgroundImage = value; }
163 [EditorBrowsable (EditorBrowsableState.Never)]
164 public new bool CausesValidation
166 get { return base.CausesValidation; }
168 if (base.CausesValidation == value)
171 base.CausesValidation = value;
172 if (CausesValidationChanged != null)
173 CausesValidationChanged (this, new EventArgs ());
177 protected override CreateParams CreateParams
179 get { return base.CreateParams; }
182 protected override ImeMode DefaultImeMode
184 get { return base.DefaultImeMode; }
187 protected override Size DefaultSize
189 get { return ThemeEngine.Current.ProgressBarDefaultSize; }
192 // Setting this property in MS .Net 1.1 does not have any visual effect and it
193 // does not fire a FontChanged event
195 [EditorBrowsable (EditorBrowsableState.Never)]
196 public override Font Font
198 get { return base.Font; }
199 set { base.Font = value; }
202 // Setting this property in MS .Net 1.1 does not have any visual effect and it
203 // does not fire a FontChanged event
205 [EditorBrowsable (EditorBrowsableState.Never)]
206 public override Color ForeColor
208 get { return base.ForeColor; }
209 set { base.ForeColor = value; }
213 [EditorBrowsable (EditorBrowsableState.Never)]
214 public new ImeMode ImeMode
216 get { return base.ImeMode; }
219 if (value == base.ImeMode)
222 base.ImeMode = value;
223 if (ImeModeChanged != null)
224 ImeModeChanged (this, EventArgs.Empty);
228 [RefreshProperties(RefreshProperties.Repaint)]
237 throw new ArgumentException(
238 string.Format("Value '{0}' must be greater than or equal to 0.", value ));
245 [RefreshProperties(RefreshProperties.Repaint)]
253 throw new ArgumentException(
254 string.Format("Value '{0}' must be greater than or equal to 0.", value ));
262 [EditorBrowsable (EditorBrowsableState.Never)]
263 public override RightToLeft RightToLeft
265 get { return base.RightToLeft; }
267 if (base.RightToLeft == value)
270 base.RightToLeft = value;
272 if (RightToLeftChanged != null)
273 RightToLeftChanged (this, EventArgs.Empty);
289 [EditorBrowsable (EditorBrowsableState.Never)]
290 public new bool TabStop
292 get { return base.TabStop; }
294 if (base.TabStop == value)
297 base.TabStop = value;
299 if (TabStopChanged != null)
300 TabStopChanged (this, EventArgs.Empty);
306 [EditorBrowsable (EditorBrowsableState.Never)]
308 public override string Text
310 get { return base.Text; }
313 if (value == base.Text)
316 if (TextChanged != null)
317 TextChanged (this, EventArgs.Empty);
331 if (value < Minimum || value > Maximum)
332 throw new ArgumentException(
333 string.Format("'{0}' is not a valid value for 'Value'. 'Value' should be between 'Minimum' and 'Maximum'", value));
341 #endregion // Protected Instance Properties
343 #region Public Instance Methods
345 protected override void CreateHandle ()
347 base.CreateHandle ();
350 public void Increment (int value)
352 int newValue = Value + value;
354 if (newValue < Minimum)
357 if (newValue > Maximum)
364 protected override void OnHandleCreated (EventArgs e)
366 base.OnHandleCreated (e);
371 public void PerformStep ()
373 if (Value >= Maximum)
376 Value = Value + Step;
380 public override string ToString()
382 return string.Format ("{0}, Minimum: {1}, Maximum: {2}, Value: {3}",
383 GetType().FullName.ToString (),
389 #endregion // Public Instance Methods
391 #region Private Instance Methods
392 private void UpdateAreas ()
394 client_area.X = client_area.Y = 2;
395 client_area.Width = Width - 4;
396 client_area.Height = Height - 4;
399 private void OnResizeTB (Object o, EventArgs e)
401 if (Width <= 0 || Height <= 0)
407 private void OnPaintPB (Object o, PaintEventArgs pevent)
409 ThemeEngine.Current.DrawProgressBar (pevent.Graphics, pevent.ClipRectangle, this);