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-2006 Novell, Inc.
23 // Jordi Mas i Hernandez jordi@ximian.com
24 // Peter Dennis Bartok pbartok@novell.com
30 using System.ComponentModel;
31 using System.Drawing.Imaging;
32 using System.Drawing.Drawing2D;
34 namespace System.Windows.Forms
36 [DefaultProperty ("Value")]
37 public sealed class ProgressBar : Control
39 #region Local Variables
44 internal Rectangle client_area = new Rectangle ();
46 internal ProgressBarStyle style;
48 #endregion // Local Variables
52 [EditorBrowsable (EditorBrowsableState.Never)]
53 public new event EventHandler BackColorChanged {
54 add { base.BackColorChanged += value; }
55 remove { base.BackColorChanged -= value; }
59 [EditorBrowsable (EditorBrowsableState.Never)]
60 public new event EventHandler BackgroundImageChanged {
61 add { base.BackgroundImageChanged += value; }
62 remove { base.BackgroundImageChanged -= value; }
66 [EditorBrowsable (EditorBrowsableState.Never)]
67 public new event EventHandler CausesValidationChanged {
68 add { base.CausesValidationChanged += value; }
69 remove { base.CausesValidationChanged -= value; }
73 [EditorBrowsable (EditorBrowsableState.Never)]
74 public new event EventHandler DoubleClick {
75 add { base.DoubleClick += value; }
76 remove { base.DoubleClick -= value; }
80 [EditorBrowsable (EditorBrowsableState.Never)]
81 public new event EventHandler Enter {
82 add { base.Enter += value; }
83 remove { base.Enter -= value; }
87 [EditorBrowsable (EditorBrowsableState.Never)]
88 public new event EventHandler FontChanged {
89 add { base.FontChanged += value; }
90 remove { base.FontChanged -= value; }
94 [EditorBrowsable (EditorBrowsableState.Never)]
95 public new event EventHandler ForeColorChanged {
96 add { base.ForeColorChanged += value; }
97 remove { base.ForeColorChanged -= value; }
101 [EditorBrowsable (EditorBrowsableState.Never)]
102 public new event EventHandler ImeModeChanged {
103 add { base.ImeModeChanged += value; }
104 remove { base.ImeModeChanged -= value; }
108 [EditorBrowsable (EditorBrowsableState.Never)]
109 public new event KeyEventHandler KeyDown {
110 add { base.KeyDown += value; }
111 remove { base.KeyDown -= value; }
115 [EditorBrowsable (EditorBrowsableState.Never)]
116 public new event KeyPressEventHandler KeyPress {
117 add { base.KeyPress += value; }
118 remove { base.KeyPress -= value; }
122 [EditorBrowsable (EditorBrowsableState.Never)]
123 public new event KeyEventHandler KeyUp {
124 add { base.KeyUp += value; }
125 remove { base.KeyUp -= value; }
129 [EditorBrowsable (EditorBrowsableState.Never)]
130 public new event EventHandler Leave {
131 add { base.Leave += value; }
132 remove { base.Leave -= value; }
136 [EditorBrowsable (EditorBrowsableState.Never)]
137 public new event PaintEventHandler Paint {
138 add { base.Paint += value; }
139 remove { base.Paint -= value; }
143 [EditorBrowsable (EditorBrowsableState.Never)]
144 public new event EventHandler RightToLeftChanged {
145 add { base.RightToLeftChanged += value; }
146 remove { base.RightToLeftChanged -= value; }
150 [EditorBrowsable (EditorBrowsableState.Never)]
151 public new event EventHandler TabStopChanged {
152 add { base.TabStopChanged += value; }
153 remove { base.TabStopChanged -= value; }
157 [EditorBrowsable (EditorBrowsableState.Never)]
158 public new event EventHandler TextChanged {
159 add { base.TextChanged += value; }
160 remove { base.TextChanged -= value; }
164 #region Public Constructors
172 base.Resize += new EventHandler (OnResizeTB);
174 SetStyle (ControlStyles.UserPaint |
175 ControlStyles.Selectable |
176 ControlStyles.ResizeRedraw |
177 ControlStyles.Opaque, false);
179 #endregion // Public Constructors
181 #region Public Instance Properties
184 [EditorBrowsable (EditorBrowsableState.Never)]
185 public override bool AllowDrop
187 get { return base.AllowDrop; }
189 base.AllowDrop = value;
193 // Setting this property in MS .Net 1.1 does not have any visual effect and it
194 // does not fire a BackColorChanged event
196 [EditorBrowsable (EditorBrowsableState.Never)]
197 public override Color BackColor
199 get { return base.BackColor; }
200 set { base.BackColor = value; }
203 // Setting this property in MS .Net 1.1 does not have any visual effect and it
204 // does not fire a BackgroundImageChanged event
206 [EditorBrowsable (EditorBrowsableState.Never)]
207 public override Image BackgroundImage
209 get { return base.BackgroundImage; }
210 set { base.BackgroundImage = value; }
214 [EditorBrowsable (EditorBrowsableState.Never)]
215 public new bool CausesValidation
217 get { return base.CausesValidation; }
218 set { base.CausesValidation = value; }
221 protected override CreateParams CreateParams
223 get { return base.CreateParams; }
226 protected override ImeMode DefaultImeMode
228 get { return base.DefaultImeMode; }
231 protected override Size DefaultSize
233 get { return ThemeEngine.Current.ProgressBarDefaultSize; }
236 // Setting this property in MS .Net 1.1 does not have any visual effect and it
237 // does not fire a FontChanged event
239 [EditorBrowsable (EditorBrowsableState.Never)]
240 public override Font Font
242 get { return base.Font; }
243 set { base.Font = value; }
246 // Setting this property in MS .Net 1.1 does not have any visual effect and it
247 // does not fire a FontChanged event
249 [EditorBrowsable (EditorBrowsableState.Never)]
250 public override Color ForeColor
252 get { return base.ForeColor; }
253 set { base.ForeColor = value; }
257 [EditorBrowsable (EditorBrowsableState.Never)]
258 public new ImeMode ImeMode
260 get { return base.ImeMode; }
261 set { base.ImeMode = value; }
264 [RefreshProperties(RefreshProperties.Repaint)]
273 throw new ArgumentException(
274 string.Format("Value '{0}' must be greater than or equal to 0.", value ));
281 [RefreshProperties(RefreshProperties.Repaint)]
289 throw new ArgumentException(
290 string.Format("Value '{0}' must be greater than or equal to 0.", value ));
298 [EditorBrowsable (EditorBrowsableState.Never)]
299 public override RightToLeft RightToLeft
301 get { return base.RightToLeft; }
302 set { base.RightToLeft = value; }
316 [MonoTODO("Implement")]
317 public ProgressBarStyle Style {
329 [EditorBrowsable (EditorBrowsableState.Never)]
330 public new bool TabStop
332 get { return base.TabStop; }
333 set { base.TabStop = value; }
337 [EditorBrowsable (EditorBrowsableState.Never)]
339 public override string Text
341 get { return base.Text; }
342 set { base.Text = value; }
353 if (value < Minimum || value > Maximum)
354 throw new ArgumentException(
355 string.Format("'{0}' is not a valid value for 'Value'. 'Value' should be between 'Minimum' and 'Maximum'", value));
363 #endregion // Protected Instance Properties
365 #region Public Instance Methods
367 protected override void CreateHandle ()
369 base.CreateHandle ();
372 public void Increment (int value)
374 int newValue = Value + value;
376 if (newValue < Minimum)
379 if (newValue > Maximum)
386 protected override void OnHandleCreated (EventArgs e)
388 base.OnHandleCreated (e);
393 public void PerformStep ()
395 if (Value >= Maximum)
398 Value = Maximum < Value + Step ? Maximum : Value + Step;
399 Refresh (); // FIXME - calculate delta and only expose that
402 public override string ToString()
404 return string.Format ("{0}, Minimum: {1}, Maximum: {2}, Value: {3}",
405 GetType().FullName.ToString (),
411 #endregion // Public Instance Methods
413 #region Private Instance Methods
414 private void UpdateAreas ()
416 client_area.X = client_area.Y = 2;
417 client_area.Width = Width - 4;
418 client_area.Height = Height - 4;
421 private void OnResizeTB (Object o, EventArgs e)
423 if (Width <= 0 || Height <= 0)
427 Invalidate(); // Invalidate the full surface, blocks will not match
430 internal override void OnPaintInternal (PaintEventArgs pevent)
432 ThemeEngine.Current.DrawProgressBar (pevent.Graphics, pevent.ClipRectangle, this);