Added a tool strip host for the tracking bar, allowing it to be embedded inside a status bar; fixed a bug in the progress reporter form that would prevent AsyncAbort() from actually being called when the user clicked on the cancel button; AsyncProgressBar no longer changes the style of the progress bar, this is now up to the user; ProgressReporterForm now switches ProgressBar between Marquee and Blocks styles on its own; various formatting enhancements

git-svn-id: file:///srv/devel/repo-conversion/nuwi@13 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
Markus Ewald 2007-12-04 20:54:42 +00:00
parent f37b946a3d
commit 1de87c2c00
6 changed files with 158 additions and 26 deletions

View file

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

View file

@ -40,12 +40,7 @@ namespace Nuclex.Windows.Forms {
// We start off being in the idle state (and thus, being invisible)
this.isIdle = true;
base.Visible = false;
// Create the tracker and attach ourselfes to its events
this.tracker = new ProgressionTracker();
this.tracker.AsyncIdleStateChanged += this.asyncIdleStateChangedDelegate;
this.tracker.AsyncProgressUpdated += this.asyncProgressUpdateDelegate;
this.Visible = false;
// Initialize the delegates we use to update the control's state and those
// we use to register ourselfes to the tracker's events
@ -56,6 +51,11 @@ namespace Nuclex.Windows.Forms {
this.asyncProgressUpdateDelegate = new EventHandler<ProgressUpdateEventArgs>(
asyncProgressUpdated
);
// Create the tracker and attach ourselfes to its events
this.tracker = new ProgressionTracker();
this.tracker.AsyncIdleStateChanged += this.asyncIdleStateChangedDelegate;
this.tracker.AsyncProgressUpdated += this.asyncProgressUpdateDelegate;
}
/// <summary>Tracks the specified progression in the tracking bar</summary>