Results 1 to 9 of 9

Thread: Cannot attach code to ToolBar Button !!!

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    52

    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.

  2. #2
    Hyperactive Member
    Join Date
    Mar 2005
    Location
    Manila, Philippines
    Posts
    486

    Re: Cannot attach code to ToolBar Button !!!

    VB Code:
    1. Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
    2. Select Case Button.Key
    3.     Case "Close"
    4.         Unload Me
    5.     Case "Save"
    6. end select
    7. end sub

  3. #3
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Cannot attach code to ToolBar Button !!!

    An example...

    Button.Key is the name of the button in your toolbar...
    VB Code:
    1. Private Sub tbToolBar_ButtonClick(ByVal Button As MSComCtlLib.Button)
    2.     On Error Resume Next
    3.     Select Case Button.Key
    4.         Case "New"
    5.             LoadNewDoc
    6.         Case "Open"
    7.             mnuFileOpen_Click
    8.         Case "Save"
    9.             mnuFileSave_Click
    10.         Case "Print"
    11.             mnuFilePrint_Click
    12.         Case "Cut"
    13.             mnuEditCut_Click
    14.         Case "Copy"
    15.             mnuEditCopy_Click
    16.         Case "Paste"
    17.             mnuEditPaste_Click
    18.         Case "Bold"
    19.             ActiveForm.rtfText.SelBold = Not ActiveForm.rtfText.SelBold
    20.             Button.Value = IIf(ActiveForm.rtfText.SelBold, tbrPressed, tbrUnpressed)
    21.         Case "Italic"
    22.             ActiveForm.rtfText.SelItalic = Not ActiveForm.rtfText.SelItalic
    23.             Button.Value = IIf(ActiveForm.rtfText.SelItalic, tbrPressed, tbrUnpressed)
    24.         Case "Underline"
    25.             ActiveForm.rtfText.SelUnderline = Not ActiveForm.rtfText.SelUnderline
    26.             Button.Value = IIf(ActiveForm.rtfText.SelUnderline, tbrPressed, tbrUnpressed)
    27.         Case "Align Left"
    28.             ActiveForm.rtfText.SelAlignment = rtfLeft
    29.         Case "Center"
    30.             ActiveForm.rtfText.SelAlignment = rtfCenter
    31.         Case "Align Right"
    32.             ActiveForm.rtfText.SelAlignment = rtfRight
    33.     End Select
    34. End Sub
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  4. #4

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    52

    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.

  5. #5
    Hyperactive Member
    Join Date
    Mar 2005
    Location
    Manila, Philippines
    Posts
    486

    Re: Cannot attach code to ToolBar Button !!!

    the case statement corresponts to the button you are clicking

  6. #6
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    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....
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  7. #7

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    52

    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.

  8. #8
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Cannot attach code to ToolBar Button !!!

    Try using the Microsoft Common Controls 6.0
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  9. #9

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    52

    [RESOLVED] Re: Cannot attach code to ToolBar Button !!!

    Thanks it worked just fine.
    Joao

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width