70-526 MCTS
ToolStripButton Control
A ToolStripButton is a toolbar button that supports images and text.
Inheritance hierarchy
System.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.ToolStripItem (abstract)
System.Windows.Forms.ToolStripButton
Hot Tracking
When you populate a ToolStrip with ToolStripButtons, the ToolStrip will
look something similar to this.

The buttons on the ToolStrip are flat, but when you hover over them they are highlighted
as per the following image. This feature is called hot tracking.

Button Style
Text or Image
The DisplayStyle property (inherited from ToolStripItem) determines whether an
image or text or both is displayed on the button. The property takes one of four values contained in
the ToolStripItemDisplayStyle enumeration.
Image - Specifies that only an image is to be rendered for this ToolStripItem.
ImageAndText - Specifies that both an image and text are to be rendered for this
ToolStripItem. (Default state)
None - Specifies that neither image nor text is to be rendered for this ToolStripItem.
Text - Specifies that only text is to be rendered for this ToolStripItem.
Although ImageAndText is the default setting, when you add a button (at least in C#
Express) the IDE defaults the property to Image.
Text Display
The way that the text appears on the button can be manipulated via three properties,
TextAlign, TextDirection and TextImageRelation.
TextAlign is inherited from ToolStripItem, it allows the text to be aligned
within the button in one of nine positions from a combination of top, middle or bottom and left,
center or right.
TextDirection is inherited from ToolStripItem, it allows the text to be
rotated within the button. The property takes one of four values contained in the
ToolStripTextDirection enumeration.
- Horizontal - Specifies horizontal text orientation.
- Inherit - Specifies that the text direction is inherited from the parent control. (Default state)
- Vertical270 - Specifies that text is to be rotated 270 degrees clockwise.
- Vertical90 - Specifies that text is to be rotated 90 degrees clockwise.
TextImageRelation is inherited from ToolStripItem, it allows the postion
of the text and picture to be set with relation to one another. The property takes one of five
values contained in the TextImageRelation enumeration.
- ImageAboveText - Specifies that the image is displayed vertically above the text of a control.
- ImageBeforeText - Specifies that the image is displayed horizontally before the text of a control. (Default state)
- Overlay - Specifies that the image and text share the same space on a control.
- TextAboveImage - Specifies that the text is displayed vertically above the image of a control.
- TextBeforeImage - Specifies that the text is displayed horizontally before the image of a control.
Events
To simply add the click event, double-click on the button. For other events select the button and open the events pane.
MSDN references
ToolStripButton - Provides a typical push button which supports both text and images.
© Publicjoe, 2007
|