Status Strips


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:

[21] Only the StatusBar tool strip has native support for springing of its tool strip items. See Chapter 4 to learn how to add this support programmatically to other strip controls.

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:

  • Image and ImageAlign display an image and align it within the displayable area.

  • Text is used to show text. (As discussed earlier, you can use an "&" (ampersand) to help users with keyboard menu navigation.)

  • DisplayStyle lets you choose whether to display text or an image or both.

  • TextImageRelation specifies where text should appear in relation to an image.

  • IsLink and LinkBehavior display the specified text as a hyperlink and govern how it acts with regard to the mouse.

  • Checked enables toggle-style button support.

  • Enabled and Visible determine whether the item can be chosen or whether it will be shown, respectively.

  • Spring specifies whether the ToolStripStatusLabel fills as much of the StatusStrip as possible, instead of at the same width as ToolStripStatusLabel's contents.

  • MergeAction and MergeIndex are MDI-related (discussed next).

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.




Windows Forms 2.0 Programming
Windows Forms 2.0 Programming (Microsoft .NET Development Series)
ISBN: 0321267966
EAN: 2147483647
Year: 2006
Pages: 216

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net