I'm using the VB6 Standard Toolbar Control. I would like to basically do this:

Private Sub MDIForm1.Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)

Which cannot be done. I'm looking for a some along these line.

I have tried this code in a timer, but it seems to make the button click erratic (sometimes more then one click at a time), so I cannot use it.

If MDIForm1.Toolbar1.Buttons(5).Value = tbrPressed Then
Call cmdPlay_Click
End If

Does anyone have any idea on how to achieve what I'm trying to accomplish?

Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
Select Case Toolbar1.Buttons.Item(Button.Index).Index
    Case 1
         MsgBox "save"
    Case 2
         Form2.Show
            
End Select
End Sub

case 1 = its button index, start with 1

commented: :D +4

IS there a way to do the code you just posted but from a form that does not include the toolbar?

Ie:

MDIForm1 has the toolbar

Form1 has the button code

hi jaydc, i didn't understand what the problem is..
are you want to button on toolbar control can be pressed right or not?
sorry,i just cant understand the problem...

bacially the problem is.

I have a toolbar in a MDIForm called MDIForm1

Most of the code of my project is located in Form1

I want to have form1 have the code, but the toolbar to located in MDIForm1.

when I use this code in form1, it does not work.

Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)

    Select Case Button.Key
    
        Case "save"
            txtButtonPressed.Text = "Save button pressed"

        Case "open"
            txtButtonPressed.Text = "Open button pressed"
            
        Case "new"
            txtButtonPressed.Text = "New button pressed"

        Case Else
            txtButtonPressed.Text = "button number " & Button.Index & " pressed"
    
    End Select

End Sub

I would like this code to be located in Form1, and refer a toolbar in MDIForm1.
I was thinking something like this.

Private Sub MDIForm1.Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)

    Select Case Button.Key
    
        Case "save"
            txtButtonPressed.Text = "Save button pressed"

        Case "open"
            txtButtonPressed.Text = "Open button pressed"
            
        Case "new"
            txtButtonPressed.Text = "New button pressed"

        Case Else
            txtButtonPressed.Text = "button number " & Button.Index & " pressed"
    
    End Select

End Sub

but you can't do that!.. How can I do it?

Sounds to me like you want to sunchronize the toolbar on all the mdi forms. Try looping through the forms collection:

If you can identify each mdi form by name then you can use:

For Each frm In Forms
If frm.Name = "mdiform" Then
frm.Toolbar1.Buttons(5).Value = tbrPressed
End If
Next

If you can't specifically identify the mdi forms, use:

On Error Resume Next
For Each frm In Forms
frm.Toolbar1.Buttons(5).Value = tbrPressed
Next

I would also use Keys for your buttons, so if you change button positions in the toolbar, you won't have to redo a lot of code. You can assign each button a key. Then instead of referencing them by number you can reference them by name.

For example:
Toolbar1.Buttons(5) or Toolbar1.Buttons("Play")

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.