ToolStripButton
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 |
A ToolStripButton is a toolbar button that supports images and text.
Inheritance hierarchy
System.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.ToolStripItem
System.Windows.Forms.ToolStripButton
Useful properties
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 thisToolStripItem. -
ImageAndText- Specifies that both an image and text are to be rendered for thisToolStripItem. (Default state) -
None- Specifies that neither image nor text is to be rendered for thisToolStripItem. -
Text- Specifies that only text is to be rendered for thisToolStripItem.
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.
-
TextAlignis inherited fromToolStripItem, 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.
-
TextDirectionis inherited fromToolStripItem, it allows the text to be rotated within the button. The property takes one of four values contained in theToolStripTextDirectionenumeration.-
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.
-
-
TextImageRelationis inherited fromToolStripItem, 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 theTextImageRelationenumeration.-
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 resources
|



