ToolStrip Technology Summary
This topic summarizes information about the
ToolStrip control and the classes that support its use.
ToolStrip control and its associated classes provide a complete solution for creating toolbars, status bars, and menus.
ToolStrip control and its associated classes, you can create advanced toolbar functionality that has consistent and professional appearance and behavior. The
ToolStrip control and classes offer the following improvements over previous controls:
A more consistent event model.
A more consistent design-time behavior that contains task lists and item collection editors.
Custom rendering with
Built-in rafting (sharing of horizontal or vertical space within the tool area when docked) with the
Design-time and run-time reordering of items with the AllowItemReorder property.
Relocation of items to an overflow menu with the CanOverflow property.
Completely configurable control location with the
ToolStrip, traditional, or custom controls using
ToolStrip is the extensible base class for
StatusStrip. These controls are ToolStripItem containers that inherit common behavior and event handling, extended so that each implementation deals with the behavior that is appropriate for it. Controls that derive from ToolStripItem are listed in the following table. The base
ToolStrip class handles painting, user input, and drag-and-drop events for these controls.
StatusStrip controls replace the previous toolbar, menu, shortcut menu, and status bar controls, although those controls are retained for backward compatibility.
ToolStrip Classes at a Glance
The following table shows the ToolStrip classes grouped by technology area.
|Toolbar, Status, and Menu containers||ToolStrip
|Presentation and rendering||ToolStripManager
ToolStrip Design-Time Features
The ToolStrip family of controls provides a rich set of tools and templates for in-place editing and defining the foundation of the user interface so that you can quickly create a working application.
Task Dialog Boxes
In Visual Studio, clicking the smart tag on a control in the designer displays a task list for convenient access to many frequently used commands.
Items Collection Editors
In Visual Studio, when you click Edit Items on the task list or right-click the control and select Edit Items in the shortcut menu, the collection editor for the control is displayed. Collection editors let you add, remove, and reorder items that the control contains. You can also view and change the properties for the control and the control's items.
The ToolStripControlHost class provides built-in wrappers for ToolStripComboBox, ToolStripTextBox, and ToolStripProgressBar controls. You can also host any other existing or COM control in a ToolStripControlHost.
For an example of control hosting, see How to: Wrap a Windows Forms Control with ToolStripControlHost.
ToolStrip classes implement a rendering scheme that is significantly different from other Windows Forms controls. With this scheme, you can easily apply styles and themes.
To apply a style to a ToolStrip and all the ToolStripItem objects it contains, you do not have to handle the Paint event for each item. Instead, you can set the RenderMode property to one of the ToolStripRenderMode values other than Custom. Alternatively, you can set the Renderer directly to any class that inherits from the ToolStripRenderer class. Setting this property automatically sets the RenderMode.
You can apply the same style to multiple ToolStrip objects in the same application by setting the RenderMode to ManagerRenderMode and setting the RenderMode or Renderer property to ToolStripManagerRenderMode that you want or ToolStripRenderer value, respectively.
For examples of rendering, see How to: Create and Set a Custom Renderer for the ToolStrip Control in Windows Forms.
Styles and Themes
ToolStrip and associated classes provide an easy way to support visual styles and custom appearance that do not require overriding the OnPaint methods for each item. Use the DisplayStyle and the RenderMode and Renderer properties.
Rafting and Docking
Rafting is the ability of toolbars to share horizontal or vertical space. A Windows form can have a ToolStripContainer that in turn has panels on the form's left, right, top, and bottom sides for positioning and rafting ToolStrip, MenuStrip, and StatusStrip controls. Multiple ToolStrip controls stack vertically if you put them in the left or right ToolStripContainer. They stack horizontally if you put them in the top or bottom ToolStripContainer. You can use the central ToolStripContentPanel of the ToolStripContainer to position traditional controls on the form.
Docking is the specifying of a control's simple location on the form's left, right, top, or bottom side.
Most of the ToolStrip controls can be docked to the form like other controls instead of using rafting. You can also specify that a ToolStrip control be freely positioned on the form by removing it from its ToolStripContainer and setting its
Dock property to
None, or you can specify its absolute position by setting the respective Location property. See How to: Move a ToolStrip Out of a ToolStripContainer onto a Form.
Use one or more ToolStripPanel controls for more flexibility, especially for Multiple Document Interface (MDI) applications, or if you do not need a ToolStripContainer. A ToolStripPanel provides a dockable space for locating and rafting ToolStrip controls but not traditional controls. By default, the ToolStripPanel does not appear in the designer Toolbox, but you can put it there by right-clicking the Toolbox, and then click Choose Items. You can also programmatically access the ToolStripPanel like any other class.