namespace System.Windows.Forms
{
[DefaultProperty ("Value")]
-#if NET_2_0
[DefaultBindingProperty ("Value")]
[ClassInterface (ClassInterfaceType.AutoDispatch)]
[ComVisible (true)]
-#endif
- public
-#if !NET_2_0
- sealed
-#endif
- class ProgressBar : Control
+ public class ProgressBar : Control
{
#region Local Variables
private int maximum;
internal int val;
internal DateTime start = DateTime.Now;
internal Rectangle client_area = new Rectangle ();
-#if NET_2_0
internal ProgressBarStyle style;
Timer marquee_timer;
bool right_to_left_layout;
-#endif
-
-#if NET_2_0
private static readonly Color defaultForeColor = SystemColors.Highlight;
-#endif
#endregion // Local Variables
#region events
-
static object RightToLeftLayoutChangedEvent = new object ();
-
-#if ONLY_1_1
- [Browsable (false)]
- [EditorBrowsable (EditorBrowsableState.Never)]
- public new event EventHandler BackColorChanged {
- add { base.BackColorChanged += value; }
- remove { base.BackColorChanged -= value; }
- }
-#endif
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
remove { base.BackgroundImageChanged -= value; }
}
-#if NET_2_0
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
- public event EventHandler BackgroundImageLayoutChanged {
+ public new event EventHandler BackgroundImageLayoutChanged {
add { base.BackgroundImageLayoutChanged += value; }
remove { base.BackgroundImageLayoutChanged -= value; }
}
-#endif
-
+
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
public new event EventHandler CausesValidationChanged {
remove { base.FontChanged -= value; }
}
-#if ONLY_1_1
- [Browsable (false)]
- [EditorBrowsable (EditorBrowsableState.Never)]
- public new event EventHandler ForeColorChanged {
- add { base.ForeColorChanged += value; }
- remove { base.ForeColorChanged -= value; }
- }
-#endif
-
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
public new event EventHandler ImeModeChanged {
add { base.Leave += value; }
remove { base.Leave -= value; }
}
-
-#if NET_2_0
+
[EditorBrowsable(EditorBrowsableState.Never)]
[Browsable(false)]
- public event MouseEventHandler MouseDoubleClick {
+ public new event MouseEventHandler MouseDoubleClick {
add { base.MouseDoubleClick += value; }
remove { base.MouseDoubleClick -= value; }
}
-
+
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
- public event EventHandler PaddingChanged {
+ public new event EventHandler PaddingChanged {
add { base.PaddingChanged += value; }
remove { base.PaddingChanged -= value; }
}
-#endif
-
+
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
public new event PaintEventHandler Paint {
remove { base.Paint -= value; }
}
-#if ONLY_1_1
- [Browsable (false)]
- [EditorBrowsable (EditorBrowsableState.Never)]
- public new event EventHandler RightToLeftChanged {
- add { base.RightToLeftChanged += value; }
- remove { base.RightToLeftChanged -= value; }
- }
-#endif
-#if NET_2_0
- public new event EventHandler RightToLeftLayoutChanged {
+ public event EventHandler RightToLeftLayoutChanged {
add { Events.AddHandler (RightToLeftLayoutChangedEvent, value); }
remove { Events.RemoveHandler (RightToLeftLayoutChangedEvent, value); }
}
-#endif
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
SetStyle (ControlStyles.UserPaint |
ControlStyles.Selectable |
ControlStyles.ResizeRedraw |
- ControlStyles.Opaque
-#if NET_2_0
- | ControlStyles.UseTextForAccessibility
-#endif
+ ControlStyles.Opaque |
+ ControlStyles.UseTextForAccessibility
, false);
-#if NET_2_0
+ force_double_buffer = true;
+
ForeColor = defaultForeColor;
-#endif
}
#endregion // Public Constructors
}
}
-#if ONLY_1_1
- // Setting this property in MS .Net 1.1 does not have any visual effect and it
- // does not fire a BackColorChanged event
- [Browsable (false)]
- [EditorBrowsable (EditorBrowsableState.Never)]
- public override Color BackColor
- {
- get { return base.BackColor; }
- set { base.BackColor = value; }
- }
-#endif
-
// Setting this property in MS .Net 1.1 does not have any visual effect and it
// does not fire a BackgroundImageChanged event
[Browsable (false)]
set { base.BackgroundImage = value; }
}
-#if NET_2_0
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public override ImageLayout BackgroundImageLayout {
get { return base.BackgroundImageLayout; }
set { base.BackgroundImageLayout = value; }
}
-#endif
+
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
public new bool CausesValidation
get { return ThemeEngine.Current.ProgressBarDefaultSize; }
}
-#if NET_2_0
[EditorBrowsable(EditorBrowsableState.Never)]
protected override bool DoubleBuffered {
get { return base.DoubleBuffered; }
set { base.DoubleBuffered = value; }
}
-#endif
+
// Setting this property in MS .Net 1.1 does not have any visual effect and it
// does not fire a FontChanged event
[Browsable (false)]
set { base.Font = value; }
}
-#if ONLY_1_1
- // Setting this property in MS .Net 1.1 does not have any visual effect and it
- // does not fire a FontChanged event
- [Browsable (false)]
- [EditorBrowsable (EditorBrowsableState.Never)]
- public override Color ForeColor
- {
- get { return base.ForeColor; }
- set { base.ForeColor = value; }
- }
-#endif
-
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
public new ImeMode ImeMode
}
set {
if (value < 0)
- throw new ArgumentException(
+ throw new ArgumentOutOfRangeException ("Maximum",
string.Format("Value '{0}' must be greater than or equal to 0.", value ));
maximum = value;
+ minimum = Math.Min (minimum, maximum);
+ val = Math.Min (val, maximum);
Refresh ();
}
}
}
set {
if (value < 0)
- throw new ArgumentException(
+ throw new ArgumentOutOfRangeException ("Minimum",
string.Format("Value '{0}' must be greater than or equal to 0.", value ));
minimum = value;
+ maximum = Math.Max (maximum, minimum);
+ val = Math.Max (val, minimum);
Refresh ();
}
}
-#if NET_2_0
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
- public Padding Padding {
+ public new Padding Padding {
get { return base.Padding; }
set { base.Padding = value; }
}
[Localizable(true)]
[DefaultValue(false)]
- [MonoTODO ("Layout is currently always from left to right")]
+ [MonoTODO ("RTL is not supported")]
public virtual bool RightToLeftLayout {
get { return right_to_left_layout;}
set {
}
}
}
-#endif
-
-#if ONLY_1_1
- [Browsable (false)]
- [EditorBrowsable (EditorBrowsableState.Never)]
- public override RightToLeft RightToLeft
- {
- get { return base.RightToLeft; }
- set { base.RightToLeft = value; }
- }
-#endif
[DefaultValue (10)]
public int Step
}
}
-#if NET_2_0
[Browsable (true)]
[DefaultValue (ProgressBarStyle.Blocks)]
[EditorBrowsable (EditorBrowsableState.Always)]
}
set {
- style = value;
-
- if (style == ProgressBarStyle.Marquee) {
- if (marquee_timer == null) {
- marquee_timer = new Timer ();
- marquee_timer.Interval = 10;
- marquee_timer.Tick += new EventHandler (marquee_timer_Tick);
- }
- marquee_timer.Start ();
- } else {
- if (marquee_timer != null) {
- marquee_timer.Stop ();
+ if (value != ProgressBarStyle.Blocks && value != ProgressBarStyle.Continuous
+ && value != ProgressBarStyle.Marquee)
+ throw new InvalidEnumArgumentException ("value", unchecked((int)value), typeof (ProgressBarStyle));
+ if (style != value) {
+ style = value;
+
+ if (style == ProgressBarStyle.Marquee) {
+ if (marquee_timer == null) {
+ marquee_timer = new Timer ();
+ marquee_timer.Interval = 10;
+ marquee_timer.Tick += new EventHandler (marquee_timer_Tick);
+ }
+ marquee_timer.Start ();
+ } else {
+ if (marquee_timer != null) {
+ marquee_timer.Stop ();
+ }
+ Refresh ();
}
}
}
marquee_animation_speed = value;
}
}
-#endif
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
}
set {
if (value < Minimum || value > Maximum)
-#if NET_2_0
throw new ArgumentOutOfRangeException ("Value", string.Format("'{0}' is not a valid value for 'Value'. 'Value' should be between 'Minimum' and 'Maximum'", value));
-#else
- throw new ArgumentException(string.Format("'{0}' is not a valid value for 'Value'. 'Value' should be between 'Minimum' and 'Maximum'", value));
-#endif
val = value;
Refresh ();
}
public void Increment (int value)
{
+ if (Style == ProgressBarStyle.Marquee)
+ throw new InvalidOperationException ("Increment should not be called if the style is Marquee.");
+
int newValue = Value + value;
if (newValue < Minimum)
UpdateAreas ();
}
-#if NET_2_0
protected override void OnBackColorChanged (EventArgs e)
{
base.OnBackColorChanged (e);
[EditorBrowsable(EditorBrowsableState.Advanced)]
protected virtual void OnRightToLeftLayoutChanged(EventArgs e)
{
- EventHandler eh = (EventHandler) Events [RightToLeftLayoutChangedEvent];
- if (eh != null)
- eh (this, e);
+ EventHandler eh = (EventHandler) Events [RightToLeftLayoutChangedEvent];
+ if (eh != null)
+ eh (this, e);
}
-#endif
public void PerformStep ()
{
- if (Value >= Maximum)
- return;
+ if (Style == ProgressBarStyle.Marquee)
+ throw new InvalidOperationException ("PerformStep should not be called if the style is Marquee.");
- Value = Maximum < Value + Step ? Maximum : Value + Step;
- Refresh (); // FIXME - calculate delta and only expose that
+ Increment (Step);
}
-#if NET_2_0
[EditorBrowsable (EditorBrowsableState.Never)]
public override void ResetForeColor ()
{
ForeColor = defaultForeColor;
}
-#endif
public override string ToString()
{
return string.Format ("{0}, Minimum: {1}, Maximum: {2}, Value: {3}",
- GetType().FullName.ToString (),
+ GetType().FullName,
Minimum.ToString (),
Maximum.ToString (),
Value.ToString () );