using System; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; using Nuclex.Support.Tracking; namespace Nuclex.Windows.Forms { /// Tracking bar that can be hosted in a tool strip container public class ToolStripTrackingBar : ToolStripControlHost { /// Initializes a new tool strip tracking bar public ToolStripTrackingBar() : base(createTrackingBar()) { hideControlAtRuntime(); } /// Initializes a new tool strip tracking bar with a name /// Name of the tracking bar control public ToolStripTrackingBar(string name) : base(createTrackingBar(), name) { hideControlAtRuntime(); } /// The tracking bar control being hosted by the tool strip host public TrackingBar TrackingBarControl { get { return base.Control as TrackingBar; } } /// Tracks the specified progression in the tracking bar /// Progression to be tracked public void Track(Waitable progression) { TrackingBarControl.Track(progression); } /// Tracks the specified progression in the tracking bar /// Progression to be tracked /// Weight of this progression in the total progress public void Track(Waitable progression, float weight) { TrackingBarControl.Track(progression, weight); } /// Stops tracking the specified progression /// Progression to stop tracking public void Untrack(Waitable progression) { TrackingBarControl.Untrack(progression); } /// Default size of the hosted control protected override Size DefaultSize { get { return new Size(100, 15); } } /// Default margin to leave around the control in the tool strip protected override Padding DefaultMargin { get { if((base.Owner != null) && (base.Owner is StatusStrip)) return new Padding(1, 3, 1, 3); return new Padding(1, 2, 1, 1); } } /// Creates a new tracking bar /// A new tracking bar private static TrackingBar createTrackingBar() { TrackingBar trackingBar = new TrackingBar(); trackingBar.Size = new Size(100, 15); return trackingBar; } /// Hides the control during runtime usage private void hideControlAtRuntime() { TrackingBarControl.VisibleChanged += new EventHandler(trackingBarVisibleChanged); LicenseUsageMode usageMode = System.ComponentModel.LicenseManager.UsageMode; if(usageMode == LicenseUsageMode.Runtime) base.Visible = false; } /// /// Toggles the visibility of the tool strip host when the tracking bar control's /// visibility changes. /// /// Tracking bar control whose visiblity has changed /// Not used private void trackingBarVisibleChanged(object sender, EventArgs e) { base.Visible = TrackingBarControl.Visible; } } } // namespace Nuclex.Windows.Forms