Toolbar Events

  • Thread starter Thread starter Bill English
  • Start date Start date
B

Bill English

How do I assign a method to the click event of a specific
toolbar button? When I look under ToolbarButton1 events,
all I see is disposed.
 
Double click the toolbar and some handling code will automatically be
generated for you - then add code to process which button was clicked

Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.ToolBarButtonClickEventArgs) Handles
ToolBar1.ButtonClick
If e.Button.Text = "Save" Then
' do stuff here
End If
End Sub
 
Thank you.
-----Original Message-----
Double click the toolbar and some handling code will automatically be
generated for you - then add code to process which button was clicked

Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.ToolBarButtonClickEventArgs) Handles
ToolBar1.ButtonClick
If e.Button.Text = "Save" Then
' do stuff here
End If
End Sub





.
 
* "Bill English said:
How do I assign a method to the click event of a specific
toolbar button? When I look under ToolbarButton1 events,
all I see is disposed.

\\\
Private Sub ToolBar1_ButtonClick( _
ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs _
) Handles ToolBar1.ButtonClick
Select Case True
Case e.Button Is Me.ToolBarButton1
 
Bill,
What I did is to create a ToolBarEx class that has a ToolBarButtonEx class.

The ToolBarButtonEx class has a Click event, while the TooBarEx class
overrides the onButtonClick method (handles the ButtonClick event) so that
is can have the respective ToolBarButtonEx class raise its event...

Something like:

Public Class ToolBarEx
Inherits ToolBar

Protected Overrides Sub OnButtonClick(ByVal e As
ToolBarButtonClickEventArgs)
If TypeOf e.Button Is ToolBarButtonEx Then
DirectCast(e.Button, ToolBarButtonEx).PerformClick()
End If
MyBase.OnButtonClick(e)
End Sub

<Editor(GetType(Design.ToolBarButtonExCollectionEditor),
GetType(System.Drawing.Design.UITypeEditor))> _
Public Shadows ReadOnly Property Buttons() As
ToolBar.ToolBarButtonCollection
Get
Return MyBase.Buttons()
End Get
End Property

End Class

Public Class ToolBarButtonEx
Inherits ToolBarButton

Public Event Click As EventHandler

Friend Sub PerformClick()
OnClick(EventArgs.Empty)
End Sub

Protected Overridable Sub OnClick(ByVal e As EventArgs)
RaiseEvent Click(Me, e)
End Sub

End Class

Namespace Design

Public Class ToolBarButtonExCollectionEditor
Inherits CollectionEditor

Public Sub New(ByVal type As System.Type)
MyBase.New(type)
End Sub

Protected Overrides Function CreateNewItemTypes() As
System.Type()
Return New Type() {GetType(ToolBarButtonEx)}
End Function

End Class

End Namespace


Hope this helps
Jay
 
Back
Top