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 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 public sealed class ProgressBar : Control
37 #region Local Variables
42 internal Rectangle paint_area = new Rectangle ();
43 internal Rectangle client_area = new Rectangle ();
44 #endregion // Local Variables
47 public new event EventHandler BackColorChanged;
48 public new event EventHandler BackgroundImageChanged;
\r
49 public new event EventHandler CausesValidationChanged;
50 public new event EventHandler DoubleClick;
51 public new event EventHandler Enter;
52 public new event EventHandler FontChanged;
53 public new event EventHandler ForeColorChanged;
54 public new event EventHandler ImeModeChanged;
\r
55 public new event KeyEventHandler KeyDown;
\r
56 public new event KeyPressEventHandler KeyPress;
\r
57 public new event KeyEventHandler KeyUp;
58 public new event EventHandler Leave;
59 public new event PaintEventHandler Paint;
\r
60 public new event EventHandler RightToLeftChanged;
\r
61 public new event EventHandler TabStopChanged;
62 public new event EventHandler TextChanged;
65 #region Public Constructors
73 base.Paint += new PaintEventHandler (OnPaintPB);
74 base.Resize += new EventHandler (OnResizeTB);
76 SetStyle (ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
77 SetStyle (ControlStyles.ResizeRedraw | ControlStyles.Opaque, true);
79 #endregion // Public Constructors
81 #region Public Instance Properties
\r
83 public override bool AllowDrop
\r
85 get { return base.AllowDrop; }
87 base.AllowDrop = value;
91 // Setting this property in MS .Net 1.1 does not have any visual effect and it
\r
92 // does not fires a BackColorChanged event
\r
93 public override Color BackColor
\r
95 get { return base.BackColor; }
96 set { BackColor = value; }
99 // Setting this property in MS .Net 1.1 does not have any visual effect and it
\r
100 // does not fires a BackgroundImageChanged event
\r
101 public override Image BackgroundImage
\r
103 get { return base.BackgroundImage; }
104 set {BackgroundImage = value; }
107 public new bool CausesValidation
\r
109 get { return base.CausesValidation; }
111 if (base.CausesValidation == value)
114 CausesValidation = value;
115 if (CausesValidationChanged != null)
116 CausesValidationChanged (this, new EventArgs ());
120 protected override CreateParams CreateParams
\r
122 get { return base.CreateParams; }
125 protected override ImeMode DefaultImeMode
\r
127 get { return base.DefaultImeMode; }
130 protected override Size DefaultSize
\r
132 get { return ThemeEngine.Current.ProgressBarDefaultSize; }
135 // Setting this property in MS .Net 1.1 does not have any visual effect and it
\r
136 // does not fires a FontChanged event
137 public override Font Font
\r
139 get { return base.Font; }
140 set { base.Font = value; }
143 // Setting this property in MS .Net 1.1 does not have any visual effect and it
\r
144 // does not fires a FontChanged event
145 public override Color ForeColor
\r
147 get { return base.ForeColor; }
148 set { base.ForeColor = value; }
151 public new ImeMode ImeMode
\r
153 get { return base.ImeMode; }
156 if (value == base.ImeMode)
159 base.ImeMode = value;
160 if (ImeModeChanged != null)
161 ImeModeChanged (this, EventArgs.Empty);
172 throw new ArgumentException(
173 string.Format("Value '{0}' must be greater than or equal to 0.", value ));
186 throw new ArgumentException(
187 string.Format("Value '{0}' must be greater than or equal to 0.", value ));
194 public override RightToLeft RightToLeft
\r
196 get { return base.RightToLeft; }
198 if (base.RightToLeft == value)
201 base.RightToLeft = value;
203 if (RightToLeftChanged != null)
204 RightToLeftChanged (this, EventArgs.Empty);
218 public new bool TabStop
\r
220 get { return base.TabStop; }
222 if (base.TabStop == value)
225 base.TabStop = value;
227 if (TabStopChanged != null)
228 TabStopChanged (this, EventArgs.Empty);
233 public override string Text
\r
235 get { return base.Text; }
238 if (value == base.Text)
241 if (TextChanged != null)
242 TextChanged (this, EventArgs.Empty);
255 if (value < Minimum || value > Maximum)
256 throw new ArgumentException(
257 string.Format("'{0}' is not a valid value for 'Value'. 'Value' should be between 'Minimum' and 'Maximum'", value));
265 #endregion // Protected Instance Properties
267 #region Public Instance Methods
270 public void Increment (int value)
272 int newValue = Value + value;
274 if (newValue < Minimum)
277 if (newValue > Maximum)
284 protected override void OnHandleCreated (EventArgs e)
286 base.OnHandleCreated (e);
290 CreateBuffers (Width, Height);
294 public void PerformStep ()
296 if (Value >= Maximum)
299 Value = Value + Step;
303 public override string ToString()
305 return string.Format ("{0}, Minimum: {1}, Maximum: {2}, Value: {3}",
306 GetType().FullName.ToString (),
312 #endregion // Public Instance Methods
314 #region Private Instance Methods
315 private void UpdateAreas ()
317 paint_area.X = paint_area.Y = 0;
318 paint_area.Width = Width;
319 paint_area.Height = Height;
321 client_area.X = client_area.Y = 2;
322 client_area.Width = Width - 4;
323 client_area.Height = Height - 4;
326 private void OnResizeTB (Object o, EventArgs e)
328 if (Width <= 0 || Height <= 0)
336 ThemeEngine.Current.DrawProgressBar (DeviceContext, this.ClientRectangle, this);
339 private void OnPaintPB (Object o, PaintEventArgs pevent)
341 if (Width <= 0 || Height <= 0 || Visible == false)
344 /* Copies memory drawing buffer to screen*/
346 pevent.Graphics.DrawImage (ImageBuffer, 0, 0);