Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / fx / src / WinForms / Managed / System / WinForms / ProgressBar.cs / 1 / ProgressBar.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* */ namespace System.Windows.Forms { using System.Runtime.Serialization.Formatters; using System.Runtime.Remoting; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System; using System.Security.Permissions; using System.Drawing; using System.ComponentModel; using System.ComponentModel.Design; using System.Windows.Forms; using Microsoft.Win32; using System.Runtime.InteropServices; using System.Windows.Forms.Layout; using System.Globalization; ////// /// [ ComVisible(true), ClassInterface(ClassInterfaceType.AutoDispatch), DefaultProperty("Value"), DefaultBindingProperty("Value"), SRDescription(SR.DescriptionProgressBar) ] public class ProgressBar : Control { //# VS7 205: simcooke //REMOVED: AddOnValueChanged, RemoveOnValueChanged, OnValueChanged and all designer plumbing associated with it. // OnValueChanged event no longer exists. // these four values define the range of possible values, how to navigate // through them, and the current position // private int minimum = 0; private int maximum = 100; private int step = 10; private int value = 0; //this defines marquee animation speed private int marqueeSpeed = 100; private Color defaultForeColor = SystemColors.Highlight; private ProgressBarStyle style = ProgressBarStyle.Blocks; private EventHandler onRightToLeftLayoutChanged; private bool rightToLeftLayout = false; ////// Represents a Windows progress bar control. /// ////// /// public ProgressBar() : base() { SetStyle(ControlStyles.UserPaint | ControlStyles.UseTextForAccessibility | ControlStyles.Selectable, false); ForeColor = defaultForeColor; } ////// Initializes a new instance of the ///class in its default /// state. /// /// /// /// protected override CreateParams CreateParams { [SecurityPermission(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.UnmanagedCode)] get { CreateParams cp = base.CreateParams; cp.ClassName = NativeMethods.WC_PROGRESS; if (this.Style == ProgressBarStyle.Continuous) { cp.Style |= NativeMethods.PBS_SMOOTH; } else if (this.Style == ProgressBarStyle.Marquee && !DesignMode) { cp.Style |= NativeMethods.PBS_MARQUEE; } if (RightToLeft == RightToLeft.Yes && RightToLeftLayout == true) { //We want to turn on mirroring for Form explicitly. cp.ExStyle |= NativeMethods.WS_EX_LAYOUTRTL; //Don't need these styles when mirroring is turned on. cp.ExStyle &= ~(NativeMethods.WS_EX_RTLREADING | NativeMethods.WS_EX_RIGHT | NativeMethods.WS_EX_LEFTSCROLLBAR); } return cp; } } ////// This is called when creating a window. Inheriting classes can ovveride /// this to add extra functionality, but should not forget to first call /// base.getCreateParams() to make sure the control continues to work /// correctly. /// ////// /// /// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public override bool AllowDrop { get { return base.AllowDrop; } set { base.AllowDrop = value; } } ////// /// /// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public override Image BackgroundImage { get { return base.BackgroundImage; } set { base.BackgroundImage = value; } } ////// /// [ Browsable(true), EditorBrowsable(EditorBrowsableState.Always), DefaultValue(ProgressBarStyle.Blocks), SRCategory(SR.CatBehavior), SRDescription(SR.ProgressBarStyleDescr) ] public ProgressBarStyle Style { get { return style; } set { if (style != value) { //valid values are 0x0 to 0x2 if (!ClientUtils.IsEnumValid(value, (int)value, (int)ProgressBarStyle.Blocks, (int)ProgressBarStyle.Marquee)){ throw new InvalidEnumArgumentException("value", (int)value, typeof(ProgressBarStyle)); } style = value; if (IsHandleCreated) RecreateHandle(); if (style == ProgressBarStyle.Marquee) { StartMarquee(); } } } } ////// Gets or sets the style of the ProgressBar. This is can be either Blocks or Continuous. /// ////// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] new public event EventHandler BackgroundImageChanged { add { base.BackgroundImageChanged += value; } remove { base.BackgroundImageChanged -= value; } } /// /// /// /// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public override ImageLayout BackgroundImageLayout { get { return base.BackgroundImageLayout; } set { base.BackgroundImageLayout = value; } } ////// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] new public event EventHandler BackgroundImageLayoutChanged { add { base.BackgroundImageLayoutChanged += value; } remove { base.BackgroundImageLayoutChanged -= value; } } /// /// /// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public new bool CausesValidation { get { return base.CausesValidation; } set { base.CausesValidation = value; } } /// /// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] new public event EventHandler CausesValidationChanged { add { base.CausesValidationChanged += value; } remove { base.CausesValidationChanged -= value; } } /// protected override ImeMode DefaultImeMode { get { return ImeMode.Disable; } } /// /// /// Deriving classes can override this to configure a default size for their control. /// This is more efficient than setting the size in the control's constructor. /// protected override Size DefaultSize { get { return new Size(100, 23); } } ////// /// This property is overridden and hidden from statement completion /// on controls that are based on Win32 Native Controls. /// [EditorBrowsable(EditorBrowsableState.Never)] protected override bool DoubleBuffered { get { return base.DoubleBuffered; } set { base.DoubleBuffered = value; } } ////// /// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public override Font Font { get { return base.Font; } set { base.Font = value; } } ////// Gets or sets the font of text in the ///. /// /// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] new public event EventHandler FontChanged { add { base.FontChanged += value; } remove { base.FontChanged -= value; } } /// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] new public ImeMode ImeMode { get { return base.ImeMode; } set { base.ImeMode = value; } } /// /// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public new event EventHandler ImeModeChanged { add { base.ImeModeChanged += value; } remove { base.ImeModeChanged -= value; } } /// /// [ DefaultValue(100), SRCategory(SR.CatBehavior), SRDescription(SR.ProgressBarMarqueeAnimationSpeed)] public int MarqueeAnimationSpeed { get { return marqueeSpeed; } [SuppressMessage("Microsoft.Usage", "CA2208:InstantiateArgumentExceptionsCorrectly")] set { if (value < 0) { throw new ArgumentOutOfRangeException("MarqueeAnimationSpeed must be non-negative"); } marqueeSpeed = value; if (!DesignMode) { StartMarquee(); } } } ////// Gets or sets the marquee animation speed of the ///. /// Sets the value to a positive number causes the progressBar to move, while setting it to 0 /// stops the progressBar. /// /// /// private void StartMarquee() { if (IsHandleCreated && style == ProgressBarStyle.Marquee) { if (marqueeSpeed == 0) { SendMessage(NativeMethods.PBM_SETMARQUEE, 0, marqueeSpeed); } else { SendMessage(NativeMethods.PBM_SETMARQUEE, 1, marqueeSpeed); } } } ////// Start the Marquee rolling (or stop it, if the speed = 0) /// ////// /// [ DefaultValue(100), SRCategory(SR.CatBehavior), RefreshProperties(RefreshProperties.Repaint), SRDescription(SR.ProgressBarMaximumDescr) ] public int Maximum { get { return maximum; } set { if (maximum != value) { // Ensure that value is in the Win32 control's acceptable range // Message: '%1' is not a valid value for '%0'. '%0' must be greater than %2. // Should this set a boundary for the top end too? if (value < 0) throw new ArgumentOutOfRangeException("Maximum", SR.GetString(SR.InvalidLowBoundArgumentEx, "Maximum", value.ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); if (minimum > value) minimum = value; maximum = value; if (this.value > maximum) this.value = maximum; if (IsHandleCreated) { SendMessage(NativeMethods.PBM_SETRANGE32, minimum, maximum); UpdatePos() ; } } } } ////// Gets or sets the maximum value of the ///. /// Gets or sets the maximum value of the . /// /// /// [ DefaultValue(0), SRCategory(SR.CatBehavior), RefreshProperties(RefreshProperties.Repaint), SRDescription(SR.ProgressBarMinimumDescr) ] public int Minimum { get { return minimum; } set { if (minimum != value) { // Ensure that value is in the Win32 control's acceptable range // Message: '%1' is not a valid value for '%0'. '%0' must be greater than %2. // Should this set a boundary for the top end too? if (value < 0) throw new ArgumentOutOfRangeException("Minimum", SR.GetString(SR.InvalidLowBoundArgumentEx, "Minimum", value.ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); if (maximum < value) maximum = value; minimum = value; if (this.value < minimum) this.value = minimum; if (IsHandleCreated) { SendMessage(NativeMethods.PBM_SETRANGE32, minimum, maximum); UpdatePos() ; } } } } protected override void OnBackColorChanged(EventArgs e) { base.OnBackColorChanged(e); if (IsHandleCreated) { UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.PBM_SETBKCOLOR, 0, ColorTranslator.ToWin32(BackColor)); } } protected override void OnForeColorChanged(EventArgs e) { base.OnForeColorChanged(e); if (IsHandleCreated) { UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.PBM_SETBARCOLOR, 0, ColorTranslator.ToWin32(ForeColor)); } } ////// Gets or sets the minimum value of the ///. /// /// /// [ Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) ] public new Padding Padding { get { return base.Padding; } set { base.Padding = value;} } [ Browsable(false), EditorBrowsable(EditorBrowsableState.Never) ] public new event EventHandler PaddingChanged { add { base.PaddingChanged += value; } remove { base.PaddingChanged -= value; } } ////// ///[To be supplied.] ////// /// This is used for international applications where the language /// is written from RightToLeft. When this property is true, // and the RightToLeft is true, mirroring will be turned on on the form, and /// control placement and text will be from right to left. /// [ SRCategory(SR.CatAppearance), Localizable(true), DefaultValue(false), SRDescription(SR.ControlRightToLeftLayoutDescr) ] public virtual bool RightToLeftLayout { get { return rightToLeftLayout; } set { if (value != rightToLeftLayout) { rightToLeftLayout = value; using(new LayoutTransaction(this, this, PropertyNames.RightToLeftLayout)) { OnRightToLeftLayoutChanged(EventArgs.Empty); } } } } ////// /// [SRCategory(SR.CatPropertyChanged), SRDescription(SR.ControlOnRightToLeftLayoutChangedDescr)] public event EventHandler RightToLeftLayoutChanged { add { onRightToLeftLayoutChanged += value; } remove { onRightToLeftLayoutChanged -= value; } } ///[To be supplied.] ////// /// [ DefaultValue(10), SRCategory(SR.CatBehavior), SRDescription(SR.ProgressBarStepDescr) ] public int Step { get { return step; } set { step = value; if (IsHandleCreated) SendMessage(NativeMethods.PBM_SETSTEP, step, 0); } } ////// Gets or sets the amount that a call to ////// increases the progress bar's current position. /// /// /// /// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] new public bool TabStop { get { return base.TabStop; } set { base.TabStop = value; } } ////// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] new public event EventHandler TabStopChanged { add { base.TabStopChanged += value; } remove { base.TabStopChanged -= value; } } /// /// /// /// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Bindable(false)] public override string Text { get { return base.Text; } set { base.Text = value; } } ////// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] new public event EventHandler TextChanged { add { base.TextChanged += value; } remove { base.TextChanged -= value; } } /// /// /// [ DefaultValue(0), SRCategory(SR.CatBehavior), Bindable(true), SRDescription(SR.ProgressBarValueDescr) ] public int Value { get { return value; } set { if (this.value != value) { if ((value < minimum) || (value > maximum)) throw new ArgumentOutOfRangeException("Value", SR.GetString(SR.InvalidBoundArgument, "Value", value.ToString(CultureInfo.CurrentCulture), "'minimum'", "'maximum'")); this.value = value; UpdatePos() ; } } } ////// Gets or sets the current position of the ///. /// /// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public new event EventHandler DoubleClick { add { base.DoubleClick += value; } remove { base.DoubleClick -= value; } } /// /// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public new event MouseEventHandler MouseDoubleClick { add { base.MouseDoubleClick += value; } remove { base.MouseDoubleClick -= value; } } /// /// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public new event KeyEventHandler KeyUp { add { base.KeyUp += value; } remove { base.KeyUp -= value; } } /// /// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public new event KeyEventHandler KeyDown { add { base.KeyDown += value; } remove { base.KeyDown -= value; } } /// /// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public new event KeyPressEventHandler KeyPress { add { base.KeyPress += value; } remove { base.KeyPress -= value; } } /// /// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public new event EventHandler Enter { add { base.Enter += value; } remove { base.Enter -= value; } } /// /// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public new event EventHandler Leave { add { base.Leave += value; } remove { base.Leave -= value; } } /// /// /// ProgressBar Onpaint. /// ///[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public new event PaintEventHandler Paint { add { base.Paint += value; } remove { base.Paint -= value; } } /// /// /// ///protected override void CreateHandle() { if (!RecreatingHandle) { IntPtr userCookie = UnsafeNativeMethods.ThemingScope.Activate(); try { NativeMethods.INITCOMMONCONTROLSEX icc = new NativeMethods.INITCOMMONCONTROLSEX(); icc.dwICC = NativeMethods.ICC_PROGRESS_CLASS; SafeNativeMethods.InitCommonControlsEx(icc); } finally { UnsafeNativeMethods.ThemingScope.Deactivate(userCookie); } } base.CreateHandle(); } /// /// /// public void Increment(int value) { if (this.Style == ProgressBarStyle.Marquee) { throw new InvalidOperationException(SR.GetString(SR.ProgressBarIncrementMarqueeException)); } this.value += value; // Enforce that value is within the range (minimum, maximum) if (this.value < minimum) { this.value = minimum; } if (this.value > maximum) { this.value = maximum; } UpdatePos(); } ////// Advances the current position of the ///by the /// specified increment and redraws the control to reflect the new position. /// /// /// Overridden to set up our properties. /// ///protected override void OnHandleCreated(EventArgs e) { base.OnHandleCreated(e); SendMessage(NativeMethods.PBM_SETRANGE32, minimum, maximum); SendMessage(NativeMethods.PBM_SETSTEP, step, 0); SendMessage(NativeMethods.PBM_SETPOS, value, 0); UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.PBM_SETBKCOLOR, 0, ColorTranslator.ToWin32(BackColor)); UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.PBM_SETBARCOLOR, 0, ColorTranslator.ToWin32(ForeColor)); StartMarquee(); SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(UserPreferenceChangedHandler); } /// /// /// Overridden to remove event handler. /// ///protected override void OnHandleDestroyed(EventArgs e) { SystemEvents.UserPreferenceChanged -= new UserPreferenceChangedEventHandler(UserPreferenceChangedHandler); base.OnHandleDestroyed(e); } /// /// /// [EditorBrowsable(EditorBrowsableState.Advanced)] protected virtual void OnRightToLeftLayoutChanged(EventArgs e) { if (GetAnyDisposingInHierarchy()) { return; } if (RightToLeft == RightToLeft.Yes) { RecreateHandle(); } if (onRightToLeftLayoutChanged != null) { onRightToLeftLayoutChanged(this, e); } } ///[To be supplied.] ////// /// public void PerformStep() { if (this.Style == ProgressBarStyle.Marquee) { throw new InvalidOperationException(SR.GetString(SR.ProgressBarPerformStepMarqueeException)); } Increment(step); } ////// Advances the current position of the ////// by the amount of the /// property, and redraws the control to reflect the new position. /// /// /// Resets the fore color to be based on the parent's fore color. /// [EditorBrowsable(EditorBrowsableState.Never)] public override void ResetForeColor() { ForeColor = defaultForeColor; } ////// /// Returns true if the ForeColor should be persisted in code gen. /// [EditorBrowsable(EditorBrowsableState.Never)] internal override bool ShouldSerializeForeColor() { return ForeColor != defaultForeColor; } ////// /// Returns a string representation for this control. /// ///public override string ToString() { string s = base.ToString(); return s + ", Minimum: " + Minimum.ToString(CultureInfo.CurrentCulture) + ", Maximum: " + Maximum.ToString(CultureInfo.CurrentCulture) + ", Value: " + Value.ToString(CultureInfo.CurrentCulture); } /// /// /// Sends the underlying window a PBM_SETPOS message to update /// the current value of the progressbar. /// ///private void UpdatePos() { if (IsHandleCreated) SendMessage(NativeMethods.PBM_SETPOS, value, 0); } //Note: ProgressBar doesn't work like other controls as far as setting ForeColor/ //BackColor -- you need to send messages to update the colors private void UserPreferenceChangedHandler(object o, UserPreferenceChangedEventArgs e) { if (IsHandleCreated) { UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.PBM_SETBARCOLOR, 0, ColorTranslator.ToWin32(ForeColor)); UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.PBM_SETBKCOLOR, 0, ColorTranslator.ToWin32(BackColor)); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ // // Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* */ namespace System.Windows.Forms { using System.Runtime.Serialization.Formatters; using System.Runtime.Remoting; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System; using System.Security.Permissions; using System.Drawing; using System.ComponentModel; using System.ComponentModel.Design; using System.Windows.Forms; using Microsoft.Win32; using System.Runtime.InteropServices; using System.Windows.Forms.Layout; using System.Globalization; ////// /// [ ComVisible(true), ClassInterface(ClassInterfaceType.AutoDispatch), DefaultProperty("Value"), DefaultBindingProperty("Value"), SRDescription(SR.DescriptionProgressBar) ] public class ProgressBar : Control { //# VS7 205: simcooke //REMOVED: AddOnValueChanged, RemoveOnValueChanged, OnValueChanged and all designer plumbing associated with it. // OnValueChanged event no longer exists. // these four values define the range of possible values, how to navigate // through them, and the current position // private int minimum = 0; private int maximum = 100; private int step = 10; private int value = 0; //this defines marquee animation speed private int marqueeSpeed = 100; private Color defaultForeColor = SystemColors.Highlight; private ProgressBarStyle style = ProgressBarStyle.Blocks; private EventHandler onRightToLeftLayoutChanged; private bool rightToLeftLayout = false; ////// Represents a Windows progress bar control. /// ////// /// public ProgressBar() : base() { SetStyle(ControlStyles.UserPaint | ControlStyles.UseTextForAccessibility | ControlStyles.Selectable, false); ForeColor = defaultForeColor; } ////// Initializes a new instance of the ///class in its default /// state. /// /// /// /// protected override CreateParams CreateParams { [SecurityPermission(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.UnmanagedCode)] get { CreateParams cp = base.CreateParams; cp.ClassName = NativeMethods.WC_PROGRESS; if (this.Style == ProgressBarStyle.Continuous) { cp.Style |= NativeMethods.PBS_SMOOTH; } else if (this.Style == ProgressBarStyle.Marquee && !DesignMode) { cp.Style |= NativeMethods.PBS_MARQUEE; } if (RightToLeft == RightToLeft.Yes && RightToLeftLayout == true) { //We want to turn on mirroring for Form explicitly. cp.ExStyle |= NativeMethods.WS_EX_LAYOUTRTL; //Don't need these styles when mirroring is turned on. cp.ExStyle &= ~(NativeMethods.WS_EX_RTLREADING | NativeMethods.WS_EX_RIGHT | NativeMethods.WS_EX_LEFTSCROLLBAR); } return cp; } } ////// This is called when creating a window. Inheriting classes can ovveride /// this to add extra functionality, but should not forget to first call /// base.getCreateParams() to make sure the control continues to work /// correctly. /// ////// /// /// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public override bool AllowDrop { get { return base.AllowDrop; } set { base.AllowDrop = value; } } ////// /// /// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public override Image BackgroundImage { get { return base.BackgroundImage; } set { base.BackgroundImage = value; } } ////// /// [ Browsable(true), EditorBrowsable(EditorBrowsableState.Always), DefaultValue(ProgressBarStyle.Blocks), SRCategory(SR.CatBehavior), SRDescription(SR.ProgressBarStyleDescr) ] public ProgressBarStyle Style { get { return style; } set { if (style != value) { //valid values are 0x0 to 0x2 if (!ClientUtils.IsEnumValid(value, (int)value, (int)ProgressBarStyle.Blocks, (int)ProgressBarStyle.Marquee)){ throw new InvalidEnumArgumentException("value", (int)value, typeof(ProgressBarStyle)); } style = value; if (IsHandleCreated) RecreateHandle(); if (style == ProgressBarStyle.Marquee) { StartMarquee(); } } } } ////// Gets or sets the style of the ProgressBar. This is can be either Blocks or Continuous. /// ////// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] new public event EventHandler BackgroundImageChanged { add { base.BackgroundImageChanged += value; } remove { base.BackgroundImageChanged -= value; } } /// /// /// /// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public override ImageLayout BackgroundImageLayout { get { return base.BackgroundImageLayout; } set { base.BackgroundImageLayout = value; } } ////// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] new public event EventHandler BackgroundImageLayoutChanged { add { base.BackgroundImageLayoutChanged += value; } remove { base.BackgroundImageLayoutChanged -= value; } } /// /// /// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public new bool CausesValidation { get { return base.CausesValidation; } set { base.CausesValidation = value; } } /// /// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] new public event EventHandler CausesValidationChanged { add { base.CausesValidationChanged += value; } remove { base.CausesValidationChanged -= value; } } /// protected override ImeMode DefaultImeMode { get { return ImeMode.Disable; } } /// /// /// Deriving classes can override this to configure a default size for their control. /// This is more efficient than setting the size in the control's constructor. /// protected override Size DefaultSize { get { return new Size(100, 23); } } ////// /// This property is overridden and hidden from statement completion /// on controls that are based on Win32 Native Controls. /// [EditorBrowsable(EditorBrowsableState.Never)] protected override bool DoubleBuffered { get { return base.DoubleBuffered; } set { base.DoubleBuffered = value; } } ////// /// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public override Font Font { get { return base.Font; } set { base.Font = value; } } ////// Gets or sets the font of text in the ///. /// /// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] new public event EventHandler FontChanged { add { base.FontChanged += value; } remove { base.FontChanged -= value; } } /// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] new public ImeMode ImeMode { get { return base.ImeMode; } set { base.ImeMode = value; } } /// /// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public new event EventHandler ImeModeChanged { add { base.ImeModeChanged += value; } remove { base.ImeModeChanged -= value; } } /// /// [ DefaultValue(100), SRCategory(SR.CatBehavior), SRDescription(SR.ProgressBarMarqueeAnimationSpeed)] public int MarqueeAnimationSpeed { get { return marqueeSpeed; } [SuppressMessage("Microsoft.Usage", "CA2208:InstantiateArgumentExceptionsCorrectly")] set { if (value < 0) { throw new ArgumentOutOfRangeException("MarqueeAnimationSpeed must be non-negative"); } marqueeSpeed = value; if (!DesignMode) { StartMarquee(); } } } ////// Gets or sets the marquee animation speed of the ///. /// Sets the value to a positive number causes the progressBar to move, while setting it to 0 /// stops the progressBar. /// /// /// private void StartMarquee() { if (IsHandleCreated && style == ProgressBarStyle.Marquee) { if (marqueeSpeed == 0) { SendMessage(NativeMethods.PBM_SETMARQUEE, 0, marqueeSpeed); } else { SendMessage(NativeMethods.PBM_SETMARQUEE, 1, marqueeSpeed); } } } ////// Start the Marquee rolling (or stop it, if the speed = 0) /// ////// /// [ DefaultValue(100), SRCategory(SR.CatBehavior), RefreshProperties(RefreshProperties.Repaint), SRDescription(SR.ProgressBarMaximumDescr) ] public int Maximum { get { return maximum; } set { if (maximum != value) { // Ensure that value is in the Win32 control's acceptable range // Message: '%1' is not a valid value for '%0'. '%0' must be greater than %2. // Should this set a boundary for the top end too? if (value < 0) throw new ArgumentOutOfRangeException("Maximum", SR.GetString(SR.InvalidLowBoundArgumentEx, "Maximum", value.ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); if (minimum > value) minimum = value; maximum = value; if (this.value > maximum) this.value = maximum; if (IsHandleCreated) { SendMessage(NativeMethods.PBM_SETRANGE32, minimum, maximum); UpdatePos() ; } } } } ////// Gets or sets the maximum value of the ///. /// Gets or sets the maximum value of the . /// /// /// [ DefaultValue(0), SRCategory(SR.CatBehavior), RefreshProperties(RefreshProperties.Repaint), SRDescription(SR.ProgressBarMinimumDescr) ] public int Minimum { get { return minimum; } set { if (minimum != value) { // Ensure that value is in the Win32 control's acceptable range // Message: '%1' is not a valid value for '%0'. '%0' must be greater than %2. // Should this set a boundary for the top end too? if (value < 0) throw new ArgumentOutOfRangeException("Minimum", SR.GetString(SR.InvalidLowBoundArgumentEx, "Minimum", value.ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture))); if (maximum < value) maximum = value; minimum = value; if (this.value < minimum) this.value = minimum; if (IsHandleCreated) { SendMessage(NativeMethods.PBM_SETRANGE32, minimum, maximum); UpdatePos() ; } } } } protected override void OnBackColorChanged(EventArgs e) { base.OnBackColorChanged(e); if (IsHandleCreated) { UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.PBM_SETBKCOLOR, 0, ColorTranslator.ToWin32(BackColor)); } } protected override void OnForeColorChanged(EventArgs e) { base.OnForeColorChanged(e); if (IsHandleCreated) { UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.PBM_SETBARCOLOR, 0, ColorTranslator.ToWin32(ForeColor)); } } ////// Gets or sets the minimum value of the ///. /// /// /// [ Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) ] public new Padding Padding { get { return base.Padding; } set { base.Padding = value;} } [ Browsable(false), EditorBrowsable(EditorBrowsableState.Never) ] public new event EventHandler PaddingChanged { add { base.PaddingChanged += value; } remove { base.PaddingChanged -= value; } } ////// ///[To be supplied.] ////// /// This is used for international applications where the language /// is written from RightToLeft. When this property is true, // and the RightToLeft is true, mirroring will be turned on on the form, and /// control placement and text will be from right to left. /// [ SRCategory(SR.CatAppearance), Localizable(true), DefaultValue(false), SRDescription(SR.ControlRightToLeftLayoutDescr) ] public virtual bool RightToLeftLayout { get { return rightToLeftLayout; } set { if (value != rightToLeftLayout) { rightToLeftLayout = value; using(new LayoutTransaction(this, this, PropertyNames.RightToLeftLayout)) { OnRightToLeftLayoutChanged(EventArgs.Empty); } } } } ////// /// [SRCategory(SR.CatPropertyChanged), SRDescription(SR.ControlOnRightToLeftLayoutChangedDescr)] public event EventHandler RightToLeftLayoutChanged { add { onRightToLeftLayoutChanged += value; } remove { onRightToLeftLayoutChanged -= value; } } ///[To be supplied.] ////// /// [ DefaultValue(10), SRCategory(SR.CatBehavior), SRDescription(SR.ProgressBarStepDescr) ] public int Step { get { return step; } set { step = value; if (IsHandleCreated) SendMessage(NativeMethods.PBM_SETSTEP, step, 0); } } ////// Gets or sets the amount that a call to ////// increases the progress bar's current position. /// /// /// /// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] new public bool TabStop { get { return base.TabStop; } set { base.TabStop = value; } } ////// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] new public event EventHandler TabStopChanged { add { base.TabStopChanged += value; } remove { base.TabStopChanged -= value; } } /// /// /// /// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Bindable(false)] public override string Text { get { return base.Text; } set { base.Text = value; } } ////// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] new public event EventHandler TextChanged { add { base.TextChanged += value; } remove { base.TextChanged -= value; } } /// /// /// [ DefaultValue(0), SRCategory(SR.CatBehavior), Bindable(true), SRDescription(SR.ProgressBarValueDescr) ] public int Value { get { return value; } set { if (this.value != value) { if ((value < minimum) || (value > maximum)) throw new ArgumentOutOfRangeException("Value", SR.GetString(SR.InvalidBoundArgument, "Value", value.ToString(CultureInfo.CurrentCulture), "'minimum'", "'maximum'")); this.value = value; UpdatePos() ; } } } ////// Gets or sets the current position of the ///. /// /// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public new event EventHandler DoubleClick { add { base.DoubleClick += value; } remove { base.DoubleClick -= value; } } /// /// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public new event MouseEventHandler MouseDoubleClick { add { base.MouseDoubleClick += value; } remove { base.MouseDoubleClick -= value; } } /// /// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public new event KeyEventHandler KeyUp { add { base.KeyUp += value; } remove { base.KeyUp -= value; } } /// /// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public new event KeyEventHandler KeyDown { add { base.KeyDown += value; } remove { base.KeyDown -= value; } } /// /// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public new event KeyPressEventHandler KeyPress { add { base.KeyPress += value; } remove { base.KeyPress -= value; } } /// /// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public new event EventHandler Enter { add { base.Enter += value; } remove { base.Enter -= value; } } /// /// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public new event EventHandler Leave { add { base.Leave += value; } remove { base.Leave -= value; } } /// /// /// ProgressBar Onpaint. /// ///[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public new event PaintEventHandler Paint { add { base.Paint += value; } remove { base.Paint -= value; } } /// /// /// ///protected override void CreateHandle() { if (!RecreatingHandle) { IntPtr userCookie = UnsafeNativeMethods.ThemingScope.Activate(); try { NativeMethods.INITCOMMONCONTROLSEX icc = new NativeMethods.INITCOMMONCONTROLSEX(); icc.dwICC = NativeMethods.ICC_PROGRESS_CLASS; SafeNativeMethods.InitCommonControlsEx(icc); } finally { UnsafeNativeMethods.ThemingScope.Deactivate(userCookie); } } base.CreateHandle(); } /// /// /// public void Increment(int value) { if (this.Style == ProgressBarStyle.Marquee) { throw new InvalidOperationException(SR.GetString(SR.ProgressBarIncrementMarqueeException)); } this.value += value; // Enforce that value is within the range (minimum, maximum) if (this.value < minimum) { this.value = minimum; } if (this.value > maximum) { this.value = maximum; } UpdatePos(); } ////// Advances the current position of the ///by the /// specified increment and redraws the control to reflect the new position. /// /// /// Overridden to set up our properties. /// ///protected override void OnHandleCreated(EventArgs e) { base.OnHandleCreated(e); SendMessage(NativeMethods.PBM_SETRANGE32, minimum, maximum); SendMessage(NativeMethods.PBM_SETSTEP, step, 0); SendMessage(NativeMethods.PBM_SETPOS, value, 0); UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.PBM_SETBKCOLOR, 0, ColorTranslator.ToWin32(BackColor)); UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.PBM_SETBARCOLOR, 0, ColorTranslator.ToWin32(ForeColor)); StartMarquee(); SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(UserPreferenceChangedHandler); } /// /// /// Overridden to remove event handler. /// ///protected override void OnHandleDestroyed(EventArgs e) { SystemEvents.UserPreferenceChanged -= new UserPreferenceChangedEventHandler(UserPreferenceChangedHandler); base.OnHandleDestroyed(e); } /// /// /// [EditorBrowsable(EditorBrowsableState.Advanced)] protected virtual void OnRightToLeftLayoutChanged(EventArgs e) { if (GetAnyDisposingInHierarchy()) { return; } if (RightToLeft == RightToLeft.Yes) { RecreateHandle(); } if (onRightToLeftLayoutChanged != null) { onRightToLeftLayoutChanged(this, e); } } ///[To be supplied.] ////// /// public void PerformStep() { if (this.Style == ProgressBarStyle.Marquee) { throw new InvalidOperationException(SR.GetString(SR.ProgressBarPerformStepMarqueeException)); } Increment(step); } ////// Advances the current position of the ////// by the amount of the /// property, and redraws the control to reflect the new position. /// /// /// Resets the fore color to be based on the parent's fore color. /// [EditorBrowsable(EditorBrowsableState.Never)] public override void ResetForeColor() { ForeColor = defaultForeColor; } ////// /// Returns true if the ForeColor should be persisted in code gen. /// [EditorBrowsable(EditorBrowsableState.Never)] internal override bool ShouldSerializeForeColor() { return ForeColor != defaultForeColor; } ////// /// Returns a string representation for this control. /// ///public override string ToString() { string s = base.ToString(); return s + ", Minimum: " + Minimum.ToString(CultureInfo.CurrentCulture) + ", Maximum: " + Maximum.ToString(CultureInfo.CurrentCulture) + ", Value: " + Value.ToString(CultureInfo.CurrentCulture); } /// /// /// Sends the underlying window a PBM_SETPOS message to update /// the current value of the progressbar. /// ///private void UpdatePos() { if (IsHandleCreated) SendMessage(NativeMethods.PBM_SETPOS, value, 0); } //Note: ProgressBar doesn't work like other controls as far as setting ForeColor/ //BackColor -- you need to send messages to update the colors private void UserPreferenceChangedHandler(object o, UserPreferenceChangedEventArgs e) { if (IsHandleCreated) { UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.PBM_SETBARCOLOR, 0, ColorTranslator.ToWin32(ForeColor)); UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.PBM_SETBKCOLOR, 0, ColorTranslator.ToWin32(BackColor)); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ResizingMessageFilter.cs
- LogReservationCollection.cs
- ByteStorage.cs
- PeerToPeerException.cs
- QueuePathDialog.cs
- KnownAssemblyEntry.cs
- TreeNodeCollection.cs
- ProcessHostMapPath.cs
- GridViewDeletedEventArgs.cs
- ResolveDuplex11AsyncResult.cs
- CustomAttribute.cs
- SetterBase.cs
- ConnectionStringsSection.cs
- SmiXetterAccessMap.cs
- BookmarkScopeManager.cs
- EllipseGeometry.cs
- XPathDescendantIterator.cs
- PropertyPathWorker.cs
- TextTreeNode.cs
- BitmapSizeOptions.cs
- RegexCharClass.cs
- UserInitiatedRoutedEventPermissionAttribute.cs
- SqlTransaction.cs
- AutoGeneratedFieldProperties.cs
- HTMLTextWriter.cs
- _HelperAsyncResults.cs
- Baml2006SchemaContext.cs
- DataGridViewCellConverter.cs
- Padding.cs
- JoinCqlBlock.cs
- XmlFormatExtensionPrefixAttribute.cs
- DocumentEventArgs.cs
- ProfilePropertyMetadata.cs
- CodeChecksumPragma.cs
- MultipleCopiesCollection.cs
- TagMapCollection.cs
- ApplyImportsAction.cs
- httpstaticobjectscollection.cs
- TableCellCollection.cs
- TokenBasedSetEnumerator.cs
- ListViewItemSelectionChangedEvent.cs
- PasswordPropertyTextAttribute.cs
- StaticTextPointer.cs
- ArgumentOutOfRangeException.cs
- DialogWindow.cs
- BitmapPalette.cs
- TransformPatternIdentifiers.cs
- ProxyWebPartConnectionCollection.cs
- TypeDelegator.cs
- DependentList.cs
- XmlNodeWriter.cs
- ResourcePool.cs
- AudioException.cs
- AuthenticatingEventArgs.cs
- DataGridViewDataErrorEventArgs.cs
- sqlpipe.cs
- MetabaseServerConfig.cs
- RuntimeConfig.cs
- localization.cs
- XamlClipboardData.cs
- PerformanceCounterPermissionEntry.cs
- MessageSecurityException.cs
- KeyInterop.cs
- SoapEnumAttribute.cs
- BreakRecordTable.cs
- TdsParameterSetter.cs
- InstanceCompleteException.cs
- EncryptedData.cs
- HttpResponseInternalWrapper.cs
- FormatterConverter.cs
- nulltextnavigator.cs
- InProcStateClientManager.cs
- Drawing.cs
- TokenizerHelper.cs
- HitTestFilterBehavior.cs
- SerializationEventsCache.cs
- SerializableAttribute.cs
- EventLogEntry.cs
- GridViewActionList.cs
- DayRenderEvent.cs
- ApplicationProxyInternal.cs
- QueryCacheKey.cs
- ClusterRegistryConfigurationProvider.cs
- VarRemapper.cs
- ApplicationInterop.cs
- MediaElement.cs
- TableItemStyle.cs
- CompositeKey.cs
- SafeSecurityHandles.cs
- IndexedEnumerable.cs
- OleDbPropertySetGuid.cs
- GeneralTransform3DGroup.cs
- DelimitedListTraceListener.cs
- PropertyGeneratedEventArgs.cs
- XPathDocumentIterator.cs
- EntityClassGenerator.cs
- QueueSurrogate.cs
- BitmapImage.cs
- XmlnsDictionary.cs
- UIntPtr.cs