Browse DevX
Sign up for e-mail newsletters from DevX


Master Toolbars and Menus with the New ToolStrip Control

For years, developers have complained about the difficulties involved in creating professional toolbars, menus, and status bars, notably the lack of flexibility and extensibility in the controls. The flexible and extensible new ToolStrip control in the .NET 2.0 framework promises to solve those problems by changing the underlying model.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

he upcoming .NET framework version 2.0 has new features galore, one of which is the new ToolStrip control. The ToolStrip aims to unify and replace existing toolbars, menus, and status bars. The new version offers specialized control implementations for use in dropdown menus, context menu popups, and status bar controls in Window Forms applications. To create this multipurpose control Microsoft had to completely redesign the class organization for menus and toolbars—a worthwhile effort—because the new design provides better design time support, custom rendering, built-in rafting, run-time re-ordering, and many more features. First, here's a brief overview of the new object model. ToolStrip Architecture Overview
In the previous versions of the .NET framework, Menu was the base class for Main Menu and ContextMenu controls while the ToolBar and StatusBar were specific control type implementations. In contrast, Whidbey groups these controls logically and provides an integrated base class called ToolStrip that's both rich and extensible. ToolStrip is now the base class for MenuStrip, ContextMenuStrip, and StatusStrip controls. All these controls function as item containers, inheriting common behavior and a common event model—extended appropriately so that each implementation accommodates specific behaviors. The base ToolStrip class handles painting, user input, and drag/drop events.

Figure 1. ToolStrip and ToolStripItem: The .NET framework 2.0 contains several implementations of the base ToolStrip type, each of which can contain a set of ToolStripItem controls, such as ToolStripButton, ToolStripDropDownItem, etc.
A ToolStrip is a container for ToolStripItem elements. Each individual element on the ToolStrip is a ToolStripItem that manages the layout and event model for the type it contains. For example, elements visible on the toolbar, such as buttons, text boxes, labels, or combo boxes, or visible on the menu bar, such as "File->New," each correspond to a ToolStripItem. Table 1 shows a list of ToolStripItem controls you can place within a ToolStrip.

Table 1. Common ToolStripItem Controls: The ToolStrip provides custom implementations of the controls most commonly hosted in toolbars and status bars.

Control Implementation Description
ToolStripLabel Used to display normal text, hyperlinks, and images.
ToolStripButton Provides a typical pushbutton that you can configure to support both text and images.
ToolStripComboBox A ComboBox with methods/properties to configure various styles.
ToolStripSeparator A separator that you can use to visually separate groups of ToolStripItem elements.
ToolStripDropDownButton This control provides a button which, when clicked, displays a ToolStripDropDown control. You'll implement a sample of this to get a better idea of how to use it.
ToolStripTextBox A normal textbox which can be used to enter text.
ToolStripMenuItem A special menu control built specifically for use with the MenuStrip and ContextMenuStrip controls.
ToolStripProgressBar A specialized progress bar implementation for use within a StatusStrip control.
ToolStripSplitButton A combination of normal button and a DropDownButton.
ToolStripControlHost A control that acts as a host to your customized implementations or any other Windows Form controls.

Though you can use most of the controls listed in Table 1 in all ToolStrip controls, Microsoft recommends that you use the various ToolStripItem types only within the matching ToolStrip type containers. For example, a ToolStripMenuItem is designed for use within a MenuStrip or ContextMenuStrip. Similarly, a ToolStripProgressBar is most appropriate with the StatusStrip. So while you might be able to put a ToolStripMenuItem inside a StatusStrip, you probably shouldn't. You can use a ToolStripManager to gain finer-grained control over ToolStrip rendering, and over behavior such as rafting (sharing horizontal and vertical real estate within a tool area when docked). You might also use a ToolStripManager to merge ToolStrip controls with each other or for other non-standard tasks.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date