Cannot attach code to ToolBar Button !!!
Hi all,
I'm trying to attach code to a Toolbar button, but have not been successful.
I created first an Image List and then a Toolbar where I specified the buttons.
Once the toolbar and buttons were created, I double clicked on the Toolbar button to attach the code, but the Procedure lists the following:
"
Private Sub ToolBarButton5_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick
End Sub
"
If I attach the code here, regardless of whatever button I click, the action performed will be always the same !!!
Is this a bug, or am I doing something wrong ?
Please let me know.
Regards,
Joao.
Re: Cannot attach code to ToolBar Button !!!
VB Code:
Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
Select Case Button.Key
Case "Close"
Unload Me
Case "Save"
end select
end sub
Re: Cannot attach code to ToolBar Button !!!
An example...
Button.Key is the name of the button in your toolbar...
VB Code:
Private Sub tbToolBar_ButtonClick(ByVal Button As MSComCtlLib.Button)
On Error Resume Next
Select Case Button.Key
Case "New"
LoadNewDoc
Case "Open"
mnuFileOpen_Click
Case "Save"
mnuFileSave_Click
Case "Print"
mnuFilePrint_Click
Case "Cut"
mnuEditCut_Click
Case "Copy"
mnuEditCopy_Click
Case "Paste"
mnuEditPaste_Click
Case "Bold"
ActiveForm.rtfText.SelBold = Not ActiveForm.rtfText.SelBold
Button.Value = IIf(ActiveForm.rtfText.SelBold, tbrPressed, tbrUnpressed)
Case "Italic"
ActiveForm.rtfText.SelItalic = Not ActiveForm.rtfText.SelItalic
Button.Value = IIf(ActiveForm.rtfText.SelItalic, tbrPressed, tbrUnpressed)
Case "Underline"
ActiveForm.rtfText.SelUnderline = Not ActiveForm.rtfText.SelUnderline
Button.Value = IIf(ActiveForm.rtfText.SelUnderline, tbrPressed, tbrUnpressed)
Case "Align Left"
ActiveForm.rtfText.SelAlignment = rtfLeft
Case "Center"
ActiveForm.rtfText.SelAlignment = rtfCenter
Case "Align Right"
ActiveForm.rtfText.SelAlignment = rtfRight
End Select
End Sub
Re: Cannot attach code to ToolBar Button !!!
Hi,
But I have several Buttons on my toolbar, do I need to put this code for each individual button ?
Joao.
Re: Cannot attach code to ToolBar Button !!!
the case statement corresponts to the button you are clicking
Re: Cannot attach code to ToolBar Button !!!
As I have said the Button.Key is the name of the buttons in your toolbar, you just use select case to determine which button was clicked....
Re: Cannot attach code to ToolBar Button !!!
OK, i got it.
Another question: in which namespace is the MSComCtlLib.Button defined, because I'm getting a compilation error .
Thanks.
Re: Cannot attach code to ToolBar Button !!!
Try using the Microsoft Common Controls 6.0
[RESOLVED] Re: Cannot attach code to ToolBar Button !!!
Thanks it worked just fine.
Joao