Firing Toolbar ButtonClick Event manually

B

Brian Mitchell

How do you fire a toolbar ButtonClick event manually (for a specified
button)?

I have a toolbar with 4 buttons on it and I want to fire one of the button
events when the user clicks a different button on the form.

The event for the toolbar looks like this...

Private Sub tbUsers_ButtonClick(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.ToolBarButtonClickEventArgs) Handles
tbUsers.ButtonClick
Select Case e.Button.Text

Case "WhateverTheText"
....
....
....

End Select

End Sub


When I try to fire the event manually and pass a value for e.button.text, I
get an error "Value 'Boolean' cannot be converted to
ToolBarButtonClickEventArgs"

ie..

Public Sub Button
tbUsers_ButtonClick(Me, e.Button.Text="WhateverTheText")
End Sub


Is there some other special way I have to specify what button event I want
fired?

Thanks!!
 
H

Herfried K. Wagner [MVP]

* "Brian Mitchell said:
I have a toolbar with 4 buttons on it and I want to fire one of the button
events when the user clicks a different button on the form.

The event for the toolbar looks like this...

Private Sub tbUsers_ButtonClick(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.ToolBarButtonClickEventArgs) Handles
tbUsers.ButtonClick
Select Case e.Button.Text

Case "WhateverTheText"
....
....
....

End Select

End Sub


When I try to fire the event manually and pass a value for e.button.text, I
get an error "Value 'Boolean' cannot be converted to
ToolBarButtonClickEventArgs"

Why not place the code which should be executed on button click in a
separate procedure and call this procedure directly?
 
S

Scott

The problem is that you're trying to pass in a boolean expression
(e.Button.Text="WhateverTheText" does not set anything in this context, it
is simply true or false) where you should be passing a
ToolBarButtonClickEventArgs object. Try the following...

Dim e As ToolBarButtonClickEventArgs
e.Button = tbUsers.Buttons(index of button to click)
tbUsers_ButtonClick(Me, e)
 
B

Brian Mitchell

Thank You all for the suggestions.

Scott said:
The problem is that you're trying to pass in a boolean expression
(e.Button.Text="WhateverTheText" does not set anything in this context, it
is simply true or false) where you should be passing a
ToolBarButtonClickEventArgs object. Try the following...

Dim e As ToolBarButtonClickEventArgs
e.Button = tbUsers.Buttons(index of button to click)
tbUsers_ButtonClick(Me, e)


e.button.text,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top