Hi guys, I've created a toolbar with 4 buttons...
How do i add code to a button?
Example i want the first button i added to show a msgbox when clicked the second to start a timer e.t.c
How do i add a code to each button individually?
regards,
Jamie
Printable View
Hi guys, I've created a toolbar with 4 buttons...
How do i add code to a button?
Example i want the first button i added to show a msgbox when clicked the second to start a timer e.t.c
How do i add a code to each button individually?
regards,
Jamie
Well, pretty much just as described in the VB6 docs.
Simple example with 3 buttons, Key values set to One, Two, Three:
Code:Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
With Button
'Using .Key, or use .Index though it can be more work to manage
'as you maintain your program over time.
Select Case .Key
Case "One"
MsgBox "One"
Case "Two"
MsgBox "Two"
Case "Three"
MsgBox "Three"
End Select
End With
End Sub
Fantastic, one last question. When case three is pressed how can i mkae the caption of that button change from "Mute" to "Unmute" ?
Thanks
Jamie
That shouldn't be a problem. The Button objects have a Caption property that appears to be read/write at runtime.
try the followingCode:
Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
With Button
'Using .Key, or use .Index though it can be more work to manage
'as you maintain your program over time.
Select Case .Key
Case "One"
MsgBox "One"
Case "Two"
MsgBox "Two"
Case "Three"
MsgBox "Three"
.caption="Unmute"
End Select
End With
End Sub
Brilliant stuff pal, Really appreciate that!
I've tried doing an if statement but does not seem to work?
I did
if .caption = "mute mic" then
.caption = "Unmute mic"
Else :
.caption ="mute mic"
End if
I basically want it so when it's clicked the caption changes from mute mic to unmute mic. Then when clicked again and unpressed it changes from Unmute mic back to mute mic.
Any ideas?
Any ideas ?