Whereas tool strips provide visual shortcuts to application commands, status strips provide visual shortcuts to details about application status and context. For example, VS05 itself uses the status strip effectively by providing information such as row and column positions when you're editing, and both textual and graphical cues when an application build is in progress, as shown in Figure 2.28. Figure 2.28. VS05 Build Progress Reported Via Status Strip
Windows Forms provides a StatusStrip control that you can use to similar effect, simply by dragging it onto your form and configuring as needed. StatusStrip is a container for zero or more status strip items, including ToolStripStatusLabel, ToolStripProgressBar, ToolStripDropDownButton, and ToolStripSplitButton. I've re-created VS05's status strip compilation experience using a text-only ToolStripStatusLabel to display the progress text, a ToolStripProgressBar to display compilation progress, and an image-only ToolStripStatusLabel with an appropriate animated GIF. These are shown in the Windows Forms Designer in Figure 2.29. Figure 2.29. StatusStrip with a Text Panel, a Progress Strip, and a Panel with an Animated GIF
Note that ToolStripStatusLabel consumes the space not filled by the ToolStripProgressBar and the second ToolStripStatusLabel combined. To do this, you set its Spring property to true. Springing is a nice way to keep tool strip items on the status strip spaced for maximum effect, called springing. [21] Also note that you should hide ToolStripProgressBar and the second ToolStripLabel until required by setting their Visible properties to true. This hides both items in the Windows Forms Designer unless their host, StatusStrip, is selected, as is the case in Figure 2.29. All these StatusStrip items are used during a simulated build process:
delegate void BuildProgress(object sender, int progressPercent); ... // MainForm.Designer.cs partial class MainForm : Form { event BuildProgress BuildProgress; event EventHandler BuildComplete; void rebuildButton_Click(object sender, EventArgs e) { // Kick rebuild off this.readyToolStripStatusLabel.Text = "Rebuild All started..."; this.animationToolStripStatusLabel.Visible = true; this.statusToolStripProgressBar.Visible = true; this.buildSimulatorTimer.Enabled = true; this.BuildProgress += BuildProgressHandler; this.BuildComplete += BuildCompleteHandler; } void buildSimulatorTimer_Tick(object sender, EventArgs e) { // Report progress this.readyToolStripStatusLabel.Text = "Build Progress"; BuildProgress(this, this.statusToolStripProgressBar.Value + 10); if( this.statusToolStripProgressBar.Value == 100 ) { this.buildSimulatorTimer.Enabled = false; this.statusToolStripProgressBar.Value = 0; BuildComplete(this, null); } } void BuildProgressHandler(object sender, int progress) { // Show progress this.statusToolStripProgressBar.Value = progress; } void BuildCompleteHandler(object sender, EventArgs e) { // Show completion this.readyToolStripStatusLabel.Text = "Rebuild All succeeded"; this.statusToolStripProgressBar.Visible = false; this.animationToolStripStatusLabel.Visible = false; } } As with MenuStrip and ToolStrip items, you can manipulate StatusStrip items directly. Here are the key properties and events implemented by the ToolStripStatusLabel type: namespace System.Windows.Forms { class ToolStripStatusLabel : ToolStripLabel { // Properties ToolStripStatusLabelBorderSides BorderSides { get; set; } Border3DStyle BorderStyle { get; set; } ToolStripItemDisplayStyle DisplayStyle { get; set; } virtual bool Enabled { get; set; } virtual Font Font { get; set; } virtual Image Image { get; set; } ContentAlignment ImageAlign { get; set; } MergeAction MergeAction { get; set; } int MergeIndex { get; set; } bool Spring { get; set; } virtual string Text { get; set; } virtual ContentAlignment TextAlign { get; set; } virtual ToolStripTextDirection TextDirection { get; set; } TextImageRelation TextImageRelation { get; set; } string ToolTipText { get; set; } bool Visible { get; set; } // Events event EventHandler Click; } } The most interesting properties are as follows:
One other important feature of the tool strip suite of controls is their ability to merge tool strip items when operating in an MDI application. |