Freetutes.com

VB6 beginners tutorial - Learn VB6

Advanced VB6 tutorial - Learn Advanced VB6

Systems Analysis - System analysis and Design tutorial for Software Engineering


You are here: Visual Basic > Advanced VB6 tutorial > Chapter 4

ToolBar Control - Add and Remove Methods and ButtonClick Event (Visual Basic 6)

Add and Remove Methods

Buttons can be added and deleted from a toolbar at runtime by using the Add and Remove methods. The Add method of the Buttons Collection has the following syntax:

Toolbar1.Buttons.Add(index, key, caption, style, image)

Index is the position at which you want to insert the new button. If you do not specify an index, the new button will appear at the right end of the existing buttons. The key is a string value that can be used to reference the new button. The caption argument will be any text that you want to appear on the new button. Style specifies how a button will behave (as described earlier). Finally, the image argument is an integer value that corresponds to an image in the ImageList connected to the ToolBar control.

To delete an existing button from the toolbar, you can use the Remove method:

Toolbar1.Buttons.Remove index

where the Index argument is either the integer value for the Index of the Button object you wish to remove or a string value for the Key of the Button object.

ButtonClick Event

The ButtonClick event for the ToolBar control will fire whenever a user clicks on a Button object. For each toolbar there is a single ButtonClick event, not one for each button on the toolbar. The event is fired as follows:

Private Sub Toolbar1_ButtonClick(ByVal button As Button)

where the Button argument is a reference to the Button object that has been clicked. You can use this argument to determine which button was clicked by the user and what to do as a result by using a Select Case statement, as shown in Listing 4.4.

LISTING 4.4

REACTING TO A USER CLICK ON A TOOLBAR BUTTON

Private Sub Toolbar1_ButtonClick(ByVal button As Button)
Select Case button.Key
Case "Open"
' open an existing file
Case "New"
' create a new file
Case "Exit"
' close the application
End Select
End Sub

ToolBar Control topics

See Also


  

<< Previous | Contents | Next >>

Home | About Us | Privacy Policy | Contact Us

Copyright © Freetutes.com | All Rights Reserved