ToolStrip
Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio
| 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.
- Create a new project
- Add a
ToolStripto a Form - Insert Standard Items by clicking on the Smart Tag icon


- Embed in a
ToolStripContainerby clicking on the Smart Tag icon
- Select Dock Fill In Form and your form designer should look like this

- Run the application and you will be able to dock the
ToolStripon 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 theToolStripclass. Set the property totrueto allow reordering. At run time, the user holds down the ALT key and the left mouse button to drag aToolStripItemto a different location on theToolStrip.
-
-
AllowMerge- Indicates whether multipleMenuStrip,ToolStripDropDownMenu,ToolStripMenuItem, and other types can be combined.
-
-
CanOverflow- Indicates whether items in theToolStripcan be sent to an overflow menu. WhenCanOverflowisTrue(the default), aToolStripItemis sent to the drop-down overflow menu when the content of theToolStripItemexceeds the width of a horizontalToolStripor the height of a verticalToolStrip.
-
-
DefaultDropDownDirection- Represents the default direction in which aToolStripDropDowncontrol is displayed relative to theToolStrip.
-
-
DefaultShowItemToolTips- Indicates whetherToolTipsare shown for theToolStripby default.
-
-
Dock- Gets or sets which edge of the parent container aToolStripis docked to.
-
-
ImageList- Gets or sets the image list that contains the image displayed on aToolStripitem.
-
-
ImageScalingSize- Gets or sets the size, in pixels, of an image used on aToolStrip.
-
-
IsCurrentlyDragging- Indicates whether the user is currently moving theToolStripfrom oneToolStripContainerto another.
-
-
IsDropDown- Indicates whether aToolStripis aToolStripDropDowncontrol.
-
-
LayoutStyle- Indicates how theToolStriplays out its items.
-
-
OverflowButton- Gets theToolStripItemthat is the overflow button for aToolStripwith overflow enabled. When you addToolStripItemsthat require more space than is allotted to theToolStripgiven the form's current size, aToolStripOverflowButtonautomatically appears on theToolStrip.
-
-
Renderer- Gets or sets aToolStripRendererused to customize the appearance and behavior (look and feel) of aToolStrip.
-
-
RenderMode- Gets or sets the painting styles to be applied to theToolStrip.
-
-
ShowItemToolTips- Indicates whetherToolTipsare to be displayed onToolStripitems.
-
-
Stretch- Indicates whether theToolStripstretches from end to end in theToolStripContainer.
-
-
TabStop- Indicates whether the user can give the focus to an item in theToolStripusing the TAB key.
-
-
TextDirection- Gets or sets the direction in which to draw text on aToolStrip.
-
Other resources
Tool, Menu, and Status Strips—ToolStrip Basics
MSDN references
- ToolStrip Control (Windows Forms) - There are some really great How-To's on this page.
|

