ToolStrip

Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio


Jump to: navigation, search
Exam Prep. Guides
70-505 Study Guide
70-526 Study Guide

1. Forms Controls

2. Integrating Data
3. Printing/Reporting
4. Enhancing Usability
5. Asynchronous Prog.
6. Forms Controls
7. Configure/Deploy

edit
Exam 70-526 Preparation Guide: Create and configure menus.


Contents



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


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


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


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 Standard Items by clicking on the Smart Tag icon Image:SmartTagGlyph.jpg


  4. Embed in a ToolStripContainer by clicking on the Smart Tag icon Image:SmartTagGlyph.jpg

  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.


Useful properties

  • AllowItemReorder - Indicates 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 - Indicates 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.
  • DefaultDropDownDirection - Represents the default direction in which a ToolStripDropDown control is displayed relative to the ToolStrip.
  • DefaultShowItemToolTips - Indicates whether ToolTips are shown for the ToolStrip by default.
  • Dock - Gets or sets which edge of the parent container a ToolStrip is docked to.
  • ImageList - Gets or sets the image list that contains the image displayed on a ToolStrip item.
  • ImageScalingSize - Gets or sets the size, in pixels, of an image used on a ToolStrip.
  • IsCurrentlyDragging - Indicates whether the user is currently moving the ToolStrip from one ToolStripContainer to another.
  • IsDropDown - Indicates whether a ToolStrip is a ToolStripDropDown control.
  • LayoutStyle - Indicates 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.
  • ShowItemToolTips - Indicates whether ToolTips are to be displayed on ToolStrip items.
  • Stretch - Indicates whether the ToolStrip stretches from end to end in the ToolStripContainer.
  • TabStop - Indicates whether the user can give the focus to an item in the ToolStrip using the TAB key.
  • TextDirection - Gets or sets the direction in which to draw text on a ToolStrip.


Other resources

Tool, Menu, and Status Strips—ToolStrip Basics


MSDN references


Previous_Page_.gif Next_Page_.gif
© 2007-2008 Mike Kitchen



Personal tools