Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Toolbar

Status
Not open for further replies.

tcalococci

Programmer
Jul 8, 2001
4
US
I have a toolbar with no captions. When I click on one of the buttons, it calls the toolbar1_click() procedure with the parameter "Button ByVal as btnControl" with the Button variable holding the Caption text.

The problem is, I don't want captions, but without them I can't creat a Select Case structure because the Button parameter returns an empty string since it references the caption property of the button index on the toolbar.

Do I have to have captions in order to reference a particular button on the toolbar or is there another way?

Thanks.
 
Yes, there is another way. The problem that you are encountering is related to 'default properties'.

Classes - and toolbar buttons are just visual classes - have properties and methods. Normally to reference a property you use the dot operator (as in Toolbar1.Button.Height), but many classes (especially those that make up the controls that ship with VB) have a default property. This is the property that is returned if you don't bother being specific; it's a kind of shorthand.

In the case of the Button control, that default property is the caption. But the Button control has other properties; specifically it has an Index property which specifies which particular button control it is. So your case statement might look something like this:

[tt]
Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)

Select Case Button.Index
Case 1
MsgBox "First button"
Case 2
MsgBox "Second button"
Case Else
MsgBox "Don't ask me to count that high..."
End Select
End Sub
 
Thanks a lot. Exactly what I was looking for. Is there any way to change the font for the button captions?
 
One further comment is using the Button.Key property. You can assign a Key to the button in the property sheet and then do what strongm suggests:

Select Case Button.Key
Case "OpenFile"
MsgBox "Open File button"
.
.
.
.
End Select

It just makes the code easier to read and work with......

(you counld also do the same using Constants or an Enum)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top