CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: ToolBar Buttons

  1. #1
    Guest

    ToolBar Buttons

    I have created a tool bar with serveral buttons on it.
    I need to operate a button, from a routine how is the call made ?

    Thanks James




  2. #2
    Join Date
    Dec 1999
    Location
    Malaysia
    Posts
    56

    Re: ToolBar Buttons

    Hi,
    You can start by double-clicking your toolbar. This will bring up the default "Click" command, which is

    private Sub Toolbar1_ButtonClick(byval Button as MSComctlLib.Button)



    Next, you can check which button has been clicked by putting in a "Select Case" statement. For example, I have 2 buttons on my toolbar, so this is my select statement

    Select Case Button.Index > 0
    Case Button.Index = 1 'Buttons start from index of 1
    'Do something
    Msgbox "First button"
    else
    'Do something else
    Msgbox "2nd button"
    End select




    And that is how you code your toolbar! Hope that this helps...

    Cheers,

    ____________________________________
    The VB Bugs in my Life...

  3. #3
    Guest

    Re: ToolBar Buttons

    Sorry this is not what I ment I have that bit working fine.
    What I need to do is call button from a different routine, not from actually pressing the button.

    I have a button group containing two buttons one starts my program and one stops it. If an error occurs I need to stop the program therefore calling that stop button. So some how I need to call that routine with the right index specified.

    I tryed

    Toolbar1_ButtonClick(2) 'Call rotine with index = 2




    but got a type mismatch

    Please help if you can.
    Thanks

    James


  4. #4
    Join Date
    Dec 1999
    Location
    Malaysia
    Posts
    56

    Re: ToolBar Buttons

    Sorry mate...
    I'm not so sure about this one... but I do know that it is best to put your "Cancel" routine in a separate sub of your own. This is useful when somewhere else in your program needs this "Cancel" routine in the future.
    Otherwise, you can put an additional Button on a form and put some code into it. Make the button "invisible" (Command1.Visible = False). So, if you do need to get out, just call this button's "Command1_Click" routine... it works fine for me...
    Hope that this suggestion helps...

    ____________________________________
    The VB Bugs in my Life...

  5. #5
    Join Date
    Dec 1999
    Location
    Malaysia
    Posts
    56

    Re: ToolBar Buttons

    Hello again!!
    Got a solution from another mate. Anyway, your problem comes from not using the "Call" statement. According to my friend, sometimes, calling a subroutine without the call statement causes an error.
    Anyway, here is a portion of the code...

    call Toolbar1_ButtonClick(Toolbar1.Buttons.Item(2))



    Hope that this helps...
    (Thanks to chyow for this...) =)
    Cheers,


    ____________________________________
    The VB Bugs in my Life...

  6. #6
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: ToolBar Buttons

    This one of those quircks of Vb syntax.

    You can call an event procedure like you are trying.

    Dont include the braces: ie

    'either just
    Toolbar_Click 2
    'or
    Call Toolbar_Click(2)





    RK

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

Featured