8.21 Creating ToolBars

 <  Day Day Up  >  

8.21 Creating ToolBar s

You want to create a ToolBar control for your application and add buttons to the toolbar.


Technique

Drag and drop a ToolBar control from the form designer toolbox onto your Windows Form. To add buttons to the ToolBar , invoke the ToolBarButton collection editor by accessing the Buttons property in the ToolBar properties. A toolbar's buttons can contain a combination of text and images. The ImageIndex property of a toolbar button is an index value into the ImageList object associated with the ToolBar control. Recipe 8.14 demonstrates how to create an ImageList and associate it with a control.

Comments

So far in this chapter, you have seen both command-based and data-based controls. A command-based control is designed to run some sort of logic within your application when the user interacts with the control, whereas a data-based control provides a visual representation of the data your application maintains. The ToolBar , just like the MainMenu and ContextMenu controls, is command based. A ToolBar is a collection of buttons arranged in a vertical or horizontal containing bar. You can visually represent the buttons themselves using text, images, or a combination of both. Most document-centric applications use a toolbar as a shortcut to run commonly used commands.

You can add new buttons to a ToolBar by accessing the ToolBarButton editor through the Buttons collection in the property browser for the control. As with other collection editors, you can add a new button by clicking the Add button and setting the appropriate properties for the button. Furthermore, if your ToolBar control has an associated ImageList , you can set the image for the button using the ImageIndex property of the ToolBarButton object. The Style property of each toolbar button also controls how the button appears. For instance, if the Style is Separator , a button does not appear, but in its place is a slight blank space used to separate the buttons to its left and right. Other possible button styles include the ToggleButton style, which remains in the pressed state when it is clicked, and the DropDownButton style, which, when an associated context menu is defined in the button's DropDownMenu property, displays a menu when clicked.

If you want to dynamically create new buttons, you can call the Add method defined in the Buttons collection. This method contains two overloads, allowing you to specify either a regular string for the text of the button or a new ToolBarButton object. Furthermore, the order of the toolbar button objects within the Buttons collection corresponds to the order in which the buttons appear on the toolbar from left to right.

 <  Day Day Up  >  


Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net