2 // System.Windows.Forms.ProgressBar
5 // stubbed out by Jaak Simm (jaaksimm@firm.ee)
6 // Dennis Hayes (dennish@Raytek.com)
7 // Aleksey Ryabchuk (ryabchuk@yahoo.com)
9 // (C) Ximian, Inc., 2002
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System
.Drawing
.Printing
;
35 using System
.ComponentModel
;
37 namespace System
.Windows
.Forms
{
40 /// Represents a Windows progress bar control.
43 public sealed class ProgressBar
: Control
{
54 public ProgressBar() {
55 SetStyle ( ControlStyles
.Selectable
, false );
62 [EditorBrowsable (EditorBrowsableState
.Never
)]
63 public override bool AllowDrop
{
64 get { return base.AllowDrop; }
65 set { base.AllowDrop = value; }
68 [EditorBrowsable (EditorBrowsableState
.Never
)]
69 public override Color BackColor
{
70 get { return base.BackColor; }
71 set { base.BackColor = value; }
74 [EditorBrowsable (EditorBrowsableState
.Never
)]
75 public override Image BackgroundImage
{
76 get { return base.BackgroundImage; }
77 set { base.BackgroundImage = value; }
80 /// This member supports the .NET Framework infrastructure and is not intended to be used directly from your code.
81 /// public new bool CausesValidation {get; set;}
84 protected override CreateParams CreateParams
{
86 CreateParams createParams
= base.CreateParams
;
88 createParams
.ClassName
= "msctls_progress32";
90 createParams
.Style
= (int) (
91 WindowStyles
.WS_CHILD
|
92 WindowStyles
.WS_VISIBLE
|
93 WindowStyles
.WS_CLIPCHILDREN
|
94 WindowStyles
.WS_CLIPSIBLINGS
);
101 protected override ImeMode DefaultImeMode
{
102 get { return ImeMode.Disable; }
105 protected override Size DefaultSize
{
106 get { return new Size(100, 23); }
109 [EditorBrowsable (EditorBrowsableState
.Never
)]
110 public override Font Font
{
111 get { return base.Font; }
112 set { base.Font = value; }
115 [EditorBrowsable (EditorBrowsableState
.Never
)]
116 public override Color ForeColor
{
117 get { return base.ForeColor; }
118 set { base.ForeColor = value; }
121 /// This member supports the .NET Framework infrastructure and is not intended to be used directly from your code.
122 /// public new ImeMode ImeMode {get; set;}
130 throw new ArgumentException(
131 string.Format("Value '{0}' must be greater than or equal to 0.", value ));
133 if ( IsHandleCreated
)
134 Win32
.SendMessage( Handle
, (int)ProgressBarMessages
.PBM_SETRANGE32
, Minimum
, Maximum
);
144 throw new ArgumentException(
145 string.Format("Value '{0}' must be greater than or equal to 0.", value ));
147 if ( IsHandleCreated
)
148 Win32
.SendMessage( Handle
, (int)ProgressBarMessages
.PBM_SETRANGE32
, Minimum
, Maximum
);
152 /// This member supports the .NET Framework infrastructure and is not intended to be used directly from your code.
153 /// public new bool TabStop {get; set;}
155 [EditorBrowsable (EditorBrowsableState
.Never
)]
156 public override RightToLeft RightToLeft
{
157 get { return base.RightToLeft; }
158 set { base.RightToLeft = value; }
165 if ( IsHandleCreated
)
166 Win32
.SendMessage( Handle
, (int)ProgressBarMessages
.PBM_SETSTEP
, Step
, 0 );
170 [EditorBrowsable (EditorBrowsableState
.Never
)]
171 public override string Text
{
172 get { return base.Text; }
173 set { base.Text = value; }
178 if ( IsHandleCreated
)
179 val
= (int)Win32
.SendMessage ( Handle
, (int)ProgressBarMessages
.PBM_GETPOS
, 0, 0 );
183 if ( value < Minimum
|| value > Maximum
)
184 throw new ArgumentException(
185 string.Format("'{0}' is not a valid value for 'Value'. 'Value' should be between 'Minimum' and 'Maximum'", value));
189 if ( IsHandleCreated
)
190 Win32
.SendMessage(Handle
, (int)ProgressBarMessages
.PBM_SETPOS
, val
, 0);
197 protected override void CreateHandle() {
198 initCommonControlsLibrary ( );
202 public void Increment(int value) {
203 int newValue
= Value
+ value;
204 if ( newValue
< Minimum
)
206 if ( newValue
> Maximum
)
211 protected override void OnHandleCreated(EventArgs e
) {
212 base.OnHandleCreated(e
);
213 Win32
.SendMessage(Handle
, (int)ProgressBarMessages
.PBM_SETRANGE32
, Minimum
, Maximum
);
214 Win32
.SendMessage(Handle
, (int)ProgressBarMessages
.PBM_SETPOS
, Value
, 0);
215 Win32
.SendMessage(Handle
, (int)ProgressBarMessages
.PBM_SETSTEP
, Step
, 0);
218 public void PerformStep() {
219 if ( IsHandleCreated
)
220 Win32
.SendMessage(Handle
, (int)ProgressBarMessages
.PBM_STEPIT
, 0, 0);
223 public override string ToString() {
224 return string.Format ("{0}, Minimum: {1}, Maximum: {2}, Value: {3}",
225 GetType().FullName
.ToString (),
232 private void initCommonControlsLibrary ( ) {
233 if ( !RecreatingHandle
) {
234 INITCOMMONCONTROLSEX initEx
= new INITCOMMONCONTROLSEX();
235 initEx
.dwICC
= CommonControlInitFlags
.ICC_PROGRESS_CLASS
;
236 Win32
.InitCommonControlsEx(initEx
);