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
28 // $Log: ProgressBar.cs,v $
29 // Revision 1.9 2004/10/05 04:56:11 jackson
30 // Let the base Control handle the buffers, derived classes should not have to CreateBuffers themselves.
32 // Revision 1.8 2004/09/28 18:44:25 pbartok
33 // - Streamlined Theme interfaces:
34 // * Each DrawXXX method for a control now is passed the object for the
35 // control to be drawn in order to allow accessing any state the theme
38 // * ControlPaint methods for the theme now have a CP prefix to avoid
39 // name clashes with the Draw methods for controls
41 // * Every control now retrieves it's DefaultSize from the current theme
43 // Revision 1.7 2004/08/25 18:29:14 jordi
44 // new methods, properties, and fixes for progressbar
46 // Revision 1.6 2004/08/10 15:41:50 jackson
47 // Allow control to handle buffering
49 // Revision 1.5 2004/07/26 17:42:03 jordi
52 // Revision 1.4 2004/07/09 20:13:05 miguel
55 // Revision 1.3 2004/07/09 17:25:23 pbartok
56 // - Removed usage of Rectangle for drawing. Miguel pointed out it's faster
58 // Revision 1.2 2004/07/09 17:17:46 miguel
59 // 2004-07-09 Miguel de Icaza <miguel@ximian.com>
61 // * ProgressBar.cs: Fixed spelling for `block'
63 // drawProgressBar: renamed to `DrawProgressBar' to follow the coding
66 // Avoid using the += on rect.X, that exposed a bug in the compiler.
68 // Revision 1.1 2004/07/09 05:21:25 pbartok
74 using System.ComponentModel;
75 using System.Drawing.Imaging;
76 using System.Drawing.Drawing2D;
78 namespace System.Windows.Forms
80 public sealed class ProgressBar : Control
82 #region Local Variables
87 internal Rectangle paint_area = new Rectangle ();
88 internal Rectangle client_area = new Rectangle ();
89 #endregion // Local Variables
92 public new event EventHandler BackColorChanged;
93 public new event EventHandler BackgroundImageChanged;
\r
94 public new event EventHandler CausesValidationChanged;
95 public new event EventHandler DoubleClick;
96 public new event EventHandler Enter;
97 public new event EventHandler FontChanged;
98 public new event EventHandler ForeColorChanged;
99 public new event EventHandler ImeModeChanged;
\r
100 public new event KeyEventHandler KeyDown;
\r
101 public new event KeyPressEventHandler KeyPress;
\r
102 public new event KeyEventHandler KeyUp;
103 public new event EventHandler Leave;
104 public new event PaintEventHandler Paint;
\r
105 public new event EventHandler RightToLeftChanged;
\r
106 public new event EventHandler TabStopChanged;
107 public new event EventHandler TextChanged;
110 #region Public Constructors
118 base.Paint += new PaintEventHandler (OnPaintPB);
119 base.Resize += new EventHandler (OnResizeTB);
121 SetStyle (ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
122 SetStyle (ControlStyles.ResizeRedraw | ControlStyles.Opaque, true);
124 #endregion // Public Constructors
126 #region Public Instance Properties
\r
128 public override bool AllowDrop
\r
130 get { return base.AllowDrop; }
132 base.AllowDrop = value;
136 // Setting this property in MS .Net 1.1 does not have any visual effect and it
\r
137 // does not fires a BackColorChanged event
\r
138 public override Color BackColor
\r
140 get { return base.BackColor; }
141 set { BackColor = value; }
144 // Setting this property in MS .Net 1.1 does not have any visual effect and it
\r
145 // does not fires a BackgroundImageChanged event
\r
146 public override Image BackgroundImage
\r
148 get { return base.BackgroundImage; }
149 set {BackgroundImage = value; }
152 public new bool CausesValidation
\r
154 get { return base.CausesValidation; }
156 if (base.CausesValidation == value)
159 CausesValidation = value;
160 if (CausesValidationChanged != null)
161 CausesValidationChanged (this, new EventArgs ());
165 protected override CreateParams CreateParams
\r
167 get { return base.CreateParams; }
170 protected override ImeMode DefaultImeMode
\r
172 get { return base.DefaultImeMode; }
175 protected override Size DefaultSize
\r
177 get { return ThemeEngine.Current.ProgressBarDefaultSize; }
180 // Setting this property in MS .Net 1.1 does not have any visual effect and it
\r
181 // does not fires a FontChanged event
182 public override Font Font
\r
184 get { return base.Font; }
185 set { base.Font = value; }
188 // Setting this property in MS .Net 1.1 does not have any visual effect and it
\r
189 // does not fires a FontChanged event
190 public override Color ForeColor
\r
192 get { return base.ForeColor; }
193 set { base.ForeColor = value; }
196 public new ImeMode ImeMode
\r
198 get { return base.ImeMode; }
201 if (value == base.ImeMode)
204 base.ImeMode = value;
205 if (ImeModeChanged != null)
206 ImeModeChanged (this, EventArgs.Empty);
217 throw new ArgumentException(
218 string.Format("Value '{0}' must be greater than or equal to 0.", value ));
231 throw new ArgumentException(
232 string.Format("Value '{0}' must be greater than or equal to 0.", value ));
239 public override RightToLeft RightToLeft
\r
241 get { return base.RightToLeft; }
243 if (base.RightToLeft == value)
246 base.RightToLeft = value;
248 if (RightToLeftChanged != null)
249 RightToLeftChanged (this, EventArgs.Empty);
263 public new bool TabStop
\r
265 get { return base.TabStop; }
267 if (base.TabStop == value)
270 base.TabStop = value;
272 if (TabStopChanged != null)
273 TabStopChanged (this, EventArgs.Empty);
278 public override string Text
\r
280 get { return base.Text; }
283 if (value == base.Text)
286 if (TextChanged != null)
287 TextChanged (this, EventArgs.Empty);
300 if (value < Minimum || value > Maximum)
301 throw new ArgumentException(
302 string.Format("'{0}' is not a valid value for 'Value'. 'Value' should be between 'Minimum' and 'Maximum'", value));
310 #endregion // Protected Instance Properties
312 #region Public Instance Methods
315 public void Increment (int value)
317 int newValue = Value + value;
319 if (newValue < Minimum)
322 if (newValue > Maximum)
329 protected override void OnHandleCreated (EventArgs e)
331 base.OnHandleCreated (e);
335 CreateBuffers (Width, Height);
339 public void PerformStep ()
341 if (Value >= Maximum)
344 Value = Value + Step;
348 public override string ToString()
350 return string.Format ("{0}, Minimum: {1}, Maximum: {2}, Value: {3}",
351 GetType().FullName.ToString (),
357 #endregion // Public Instance Methods
359 #region Private Instance Methods
360 private void UpdateAreas ()
362 paint_area.X = paint_area.Y = 0;
363 paint_area.Width = Width;
364 paint_area.Height = Height;
366 client_area.X = client_area.Y = 2;
367 client_area.Width = Width - 4;
368 client_area.Height = Height - 4;
371 private void OnResizeTB (Object o, EventArgs e)
373 if (Width <= 0 || Height <= 0)
379 /* Disable background painting to avoid flickering, since we do our painting*/
380 protected override void OnPaintBackground (PaintEventArgs pevent)
387 ThemeEngine.Current.DrawProgressBar (DeviceContext, this.ClientRectangle, this);
390 private void OnPaintPB (Object o, PaintEventArgs pevent)
392 if (Width <= 0 || Height <= 0 || Visible == false)
395 /* Copies memory drawing buffer to screen*/
397 pevent.Graphics.DrawImage (ImageBuffer, 0, 0);