70-526 MCTS


ToolStrip

The ToolStrip control is the base class of many user interface elements for Windows Forms.

MenuStrip, ContextMenuStrip, StatusStrip, and ToolStripDropDown controls replace the previous toolbar, main menu, context menu, and status bar controls respectively.


Inheritance hierarchy

System.Object 
  System.MarshalByRefObject 
    System.ComponentModel.Component 
      System.Windows.Forms.Control 
        System.Windows.Forms.ScrollableControl 
          System.Windows.Forms.ToolStrip
            System.Windows.Forms.MenuStrip 
            System.Windows.Forms.StatusStrip 
            System.Windows.Forms.ToolStripDropDown 
              System.Windows.Forms.ToolStripDropDownMenu 
               System.Windows.Forms.ContextMenuStrip

The basics

The ToolStrip family of controls provide a common interface for Menus and Strips in Windows Forms. The ToolStrip control itself can be seen in action in any of the visual studio IDEs, under the menus. Before we explore the control, build this simple application.

  1. Create a new project
  2. Add a ToolStrip to a Form
  3. Insert a set of standard items by clicking on the Smart Tag icon and choosing Insert Standard Items.

  4. Embed the ToolStrip in a ToolStripContainer by clicking on the Smart Tag icon and choosing Embed in a ToolStripContainer.

  5. Select Dock Fill In Form and your form designer should look like this

  6. Run the application and you will be able to dock the ToolStrip on any side of the Form


Overview

The ToolStrip is a container for holding different types of controls that are derived from ToolStripItem. In the example that we just created, the ToolStrip holds a selection of buttons which are instances of ToolStripButton. Other items that can be held within the ToolStrip are:

  • ToolStripSplitButton
  • ToolStripDropDownButton
  • ToolStripLabel
  • ToolStripProgressBar
  • ToolStripSeparator
  • ToolStripComboBox
  • ToolStripTextBox
  • A ToolStrip appears by default as Office-style with a flat look. Windows XP themes are supported; however the painting of the control may be overridden.

    When the control is resized, any buttons that cannot fit on the ToolStrip are accessed via a drop down menu.

    By default, the ToolStrip is double buffered, taking advantage of the OptimizedDoubleBuffer setting.


    Important ToolStrip members

  • AllowItemReorder - Gets or sets a value indicating whether drag-and-drop and item reordering are handled privately by the ToolStrip class. Set the property to true to allow reordering. At run time, the user holds down the ALT key and the left mouse button to drag a ToolStripItem to a different location on the ToolStrip.
  • CanOverflow - Gets or sets a value indicating whether items in the ToolStrip can be sent to an overflow menu. When CanOverflow is True (the default), a ToolStripItem is sent to the drop-down overflow menu when the content of the ToolStripItem exceeds the width of a horizontal ToolStrip or the height of a vertical ToolStrip.
  • Dock - Gets or sets which edge of the parent container a ToolStrip is docked to.
  • LayoutStyle - Gets or sets a value indicating how the ToolStrip lays out its items.
  • OverflowButton - Gets the ToolStripItem that is the overflow button for a ToolStrip with overflow enabled. When you add ToolStripItems that require more space than is allotted to the ToolStrip given the form's current size, a ToolStripOverflowButton automatically appears on the ToolStrip.
  • Renderer - Gets or sets a ToolStripRenderer used to customize the appearance and behavior (look and feel) of a ToolStrip.
  • RenderMode - Gets or sets the painting styles to be applied to the ToolStrip.

  • Adding items to a ToolStrip

    There are two


    MSDN references

  • ToolStrip Class
  • ToolStrip Control (Windows Forms) - There are some really great How-To's on this page.
  • ToolStrip Sample


    << Previous Contents Next >>

    © Publicjoe, 2007