Toolbar Control

Adding Buttons

First, add the toolbar control to a form. To do this, select the toolbar item

Then, simply 'draw' it onto the form, and it will automatically stick to the top edge of your form. If you don't want it at the top, you can change the controls Align property to make it appear at the bottom, left etc...

Usually, you won't need to add buttons at run-time, as you will know exactly what you want before your program starts, so for this tutorial, we will focus on adding buttons at design-time. To do this, right click on the toolbar you have just added and click Properties. The dialog that appears allows you to modify the appearance of the toolbar control and its buttons. Click the Buttons tab, and then click Insert Button.

You will notice that a blank button automatically appears on the toolbar in the form, and the text boxes in the Properties window are enabled. The Caption property specifies the text that appears at the bottom of the button. If you leave this blank, space will be left just for the icon. For the moment, enter the text 'Open' (without the quotes). The next box lets you specify a key that uniquely identifies the button. Fill this with 'Open' too. This is all you have to specify for a button, but the table below explains the other button properties you can set.

Property Description
Index Displays the Index (position) of the button in the toolbar
ToolTipText Sets the text that appears when the mouse hovers over the button
Style Sets the button style. This will be explained later in the tutorial
Image Specifies the image in the ImageList to be displayed. This is explained in the 'Using Images' section.
Tag Allows you to store other data about the button you can use. The Toolbar control ignores this.
Visible Specifies whether the button is visible or not
Enabled Specifies whether the button is enabled or not
MixedState Specifies if the button has a 3rd state (ie not down, but not up either. If you're not sure what I mean, try it!)

Add a few more buttons for 'Save' and 'New' by clicking New Button again and filling out the values. You can move between the buttons in the property window by clicking the <> arrows next to the Index value. Once you are happy with the toolbar, click OK. Your form should now look something like this:

You might also like...

Comments

About the author

James Crowley

James Crowley United Kingdom

James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audien...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” - Brian Kernighan