using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using System.Windows.Forms.Design; using System.Drawing; using System.ComponentModel; namespace BSE.Windows.Forms { /// /// Represents a Windows progress bar control contained in a StatusStrip. /// [ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.ToolStrip | ToolStripItemDesignerAvailability.StatusStrip)] [ToolboxBitmap(typeof(System.Windows.Forms.ProgressBar))] public class ToolStripProgressBar : ToolStripControlHost { #region Events #endregion #region Constants #endregion #region FieldsPrivate #endregion #region Properties /// /// Gets the ProgressBar. /// /// /// Type: /// A ProgressBar. /// public ProgressBar ProgressBar { get { return base.Control as ProgressBar; } } /// /// Gets or sets a value indicating whether items are to be placed from right to left /// and text is to be written from right to left. /// /// /// Type: /// true if items are to be placed from right to left and text is to be written from right to left; otherwise, false. /// public override RightToLeft RightToLeft { get { return this.ProgressBar.RightToLeft; } set { this.ProgressBar.RightToLeft = value; } } /// /// Gets or sets the color used for the background rectangle for this . /// /// /// Type: /// A Color used for the background rectangle of this ToolStripProgressBar. /// [Browsable(true)] [Category("Appearance")] [Description("The color used for the background rectangle of this control.")] public Color BackgroundColor { get { return this.ProgressBar.BackgroundColor; } set { this.ProgressBar.BackgroundColor = value; } } /// /// Gets or sets the color used for the value rectangle of this control. /// Gets or sets color used for the value rectangle for this . /// /// /// Type: /// A Color used for the value rectangle for this ToolStripProgressBar. /// [Browsable(true)] [Category("Appearance")] [Description("The end color of the gradient used for the value rectangle of this control.")] public Color ValueColor { get { return this.ProgressBar.ValueColor; } set { this.ProgressBar.ValueColor = value; } } /// /// Gets or sets the foreground color of the hosted control. /// /// /// Type: /// A representing the foreground color of the hosted control. /// [Browsable(true)] [Category("Appearance")] [Description("The Foreground color used to display text on the progressbar")] public override Color ForeColor { get { return this.ProgressBar.ForeColor; } set { this.ProgressBar.ForeColor = value; } } /// /// Gets or sets the font to be used on the hosted control. /// /// /// Type: /// The Font for the hosted control. /// [Category("Appearance")] [Description("The font used to display text on the progressbar")] public override Font Font { get { return this.ProgressBar.Font; } set { this.ProgressBar.Font = value; } } /// /// Gets or sets the upper bound of the range that is defined for this . /// /// /// Type: /// An integer representing the upper bound of the range. The default is 100. /// [Category("Behavior")] [DefaultValue(100)] [RefreshProperties(RefreshProperties.All)] [Description("The upper bound of the range this progressbar is working with.")] public int Maximum { get { return this.ProgressBar.Maximum; } set { this.ProgressBar.Maximum = value; } } /// /// Gets or sets the lower bound of the range that is defined for this . /// /// /// Type: /// An integer representing the lower bound of the range. The default is 0. /// [Category("Behavior")] [DefaultValue(0)] [RefreshProperties(RefreshProperties.All)] [Description("The lower bound of the range this progressbar is working with.")] public int Minimum { get { return this.ProgressBar.Minimum; } set { this.ProgressBar.Minimum = value; } } /// /// Gets or sets the current value of the . /// /// /// Type: /// An integer representing the current value. /// [Category("Behavior")] [DefaultValue(0)] [RefreshProperties(RefreshProperties.All)] [Description("The current value for the progressbar, in the range specified by the minimum and maximum.")] public int Value { get { return this.ProgressBar.Value; } set { this.ProgressBar.Value = value; } } /// /// Gets or sets the text displayed on the . /// /// /// Type: /// A representing the display text. /// [Category("Behavior")] [Description("The text to display on the progressbar")] public override string Text { get { return this.ProgressBar.Text; } set { this.ProgressBar.Text = value; } } /// /// Gets the height and width of the ToolStripProgressBar in pixels. /// /// /// Type: /// A Point value representing the height and width. /// protected override Size DefaultSize { get { return new Size(100, 15); } } /// /// Gets the spacing between the and adjacent items. /// protected override Padding DefaultMargin { get { if ((base.Owner != null) && (base.Owner is StatusStrip)) { return new Padding(1, 3, 1, 3); } return new Padding(1, 1, 1, 2); } } #endregion #region MethodsPublic /// /// Initializes a new instance of the ToolStripProgressBar class. /// public ToolStripProgressBar() : base(CreateControlInstance()) { } #endregion #region MethodsProtected /// /// Raises the OwnerChanged event. /// /// An EventArgs that contains the event data. protected override void OnOwnerChanged(EventArgs e) { if (base.Owner != null) { base.Owner.RendererChanged += new EventHandler(OwnerRendererChanged); } base.OnOwnerChanged(e); } #endregion #region MethodsPrivate private static Control CreateControlInstance() { BSE.Windows.Forms.ProgressBar progressBar = new BSE.Windows.Forms.ProgressBar(); progressBar.Size = new Size(100, 15); return progressBar; } private void OwnerRendererChanged(object sender, EventArgs e) { ToolStripRenderer toolsTripRenderer = this.Owner.Renderer; if (toolsTripRenderer != null) { if (toolsTripRenderer is BseRenderer) { ToolStripProfessionalRenderer renderer = toolsTripRenderer as ToolStripProfessionalRenderer; if (renderer != null) { this.ProgressBar.BorderColor = renderer.ColorTable.ToolStripBorder; } if (this.Owner.GetType() != typeof(StatusStrip)) { this.Margin = new Padding(1, 1, 1, 3); } } else { this.Margin = DefaultMargin; } } } #endregion } }