Hello,
Can some one help me? I need to trigger a specific toolbar button Click event when I click menu item.
Thank you. :confused:
Printable View
Hello,
Can some one help me? I need to trigger a specific toolbar button Click event when I click menu item.
Thank you. :confused:
Hi,
Same way as you call any objects Click Event. But if you have the necessary button on the toolbar, why are you also referring to it in a Menu? Are you saying that you are not including the toolbar on your form but want to activate the code contained in one of the toolbar buttons?
Incase you're creating this at runtime then you have to do this :
VB Code:
AddHandler ToolBar1.ButtonClick, AddressOf Me.ToolBarCustomHandler Public Sub ToolBarCustomHandler(ByVal sender As system.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick 'Do your stuff here End Sub
If the toolbar buttonclick event is already created then just do this :
VB Code:
Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick Dim btn As String = e.Button.Text Select Case btn Case "Add" MsgBox("add button was clicked") Case "Edit" MsgBox("edit button was clicked") Case "Search" MsgBox("search button was clicked") End Select End Sub 'From your menuitem , you can call the edit button like this : Me.ToolBar1_ButtonClick(Me, New ToolBarButtonClickEventArgs(New ToolBarButton("Edit")))
Thank you very much it works great
:D :thumb: