As an application offers a greater number of commands, the associated menu items can become more deeply hidden within a burgeoning menu strip hierarchy. This means that users likely spend more time searching for a specific command. If you encounter this situation, you can save users time by providing access to the most commonly used commands from a tool strip, which displays them as single-click buttons. You can add a tool strip to a form by dragging a ToolStrip control onto it from the Toolbox. As with the MenuStrip control, you can manually add items on the design surface, or you can insert a standard set of tool strip buttons automatically by selecting "Insert Standard items" from the ToolStrip's smart tag, resulting in the form shown in Figure 2.27. Figure 2.27. ToolStrip with Standard Tool Strip Buttons Inserted
ToolStrip is a container for zero or more tool strip items, which are stored in the Items property of type ToolStripItemCollection. The Windows Forms Designer provides a rich selection of tool strip items for the ToolStrip, including ToolStripButton, ToolStripLabel, ToolStripSplitButton, ToolStripDropDownButton, ToolStripSeparator, ToolStripComboBox, ToolStripTextBox, and ToolStripProgressBar. The most common item is ToolStripButton, which exposes the following interesting design time properties and events: namespace System.Windows.Forms { class ToolStripButton : ToolStripItem { // Properties ToolStripItemAlignment Alignment { get; set; } bool AutoSize { get; set; } bool AutoToolTip { get; set; } bool Checked { get; set; } bool CheckOnClick { get; set; } CheckState CheckState { get; set; } ToolStripItemDisplayStyle DisplayStyle { get; set; } virtual bool Enabled { get; set; } virtual Image Image { get; set; } ContentAlignment ImageAlign { get; set; } MergeAction MergeAction { get; set; } int MergeIndex { get; set; } ToolStripItemPlacement Placement { get; } virtual bool Pressed { get; } virtual bool Selected { get; } 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 CheckedChanged; event EventHandler CheckStateChanged; event EventHandler Click; event EventHandler DoubleClick; event MouseEventHandler MouseDown; event EventHandler MouseEnter; event EventHandler MouseHover; event EventHandler MouseLeave; event MouseEventHandler MouseMove; event MouseEventHandler MouseUp; } } Here are the properties you'll encounter most often:
As with ToolStripMenuItem, the Click event handler is likely the most often used because it is fired whenever a tool strip button is clicked: void newToolStripButton_Click(object sender, EventArgs e) { MessageBox.Show("Out with the old, in with the new!", "File | New"); } |