Solved

Toolbar Problem

Posted on 2004-08-16
5
221 Views
Last Modified: 2010-04-23
how to i add events to toolbar buttons, i cant work out how to get the toolbar buttons to work
0
Comment
Question by:davidrichardson
5 Comments
 
LVL 4

Expert Comment

by:srcalc
ID: 11817374
   Private Sub ToolBar_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar.ButtonClick
        MsgBox(e.Button)
    End Sub

This will pop up a message box telling the button text that was clicked.
0
 
LVL 7

Author Comment

by:davidrichardson
ID: 11819156
That gives me the same event on all the buttons, how do I specify each button
0
 
LVL 4

Accepted Solution

by:
Daniellus83 earned 125 total points
ID: 11819455
I know this problem:


try this:

    Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick
        MsgBox(e.Button.ToString)
    End Sub


You wil see you have to extract this information from the second argument (ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs)
So if you use this code (I have a toolbar with 3 buttons; named button1,button2,button3) it will work:

    Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick
        If e.Button.Text = "Button1" Then
            MsgBox("You clicked button 1...")
        ElseIf e.Button.Text = "Button2" Then
            MsgBox("You clicked button 2...")
        ElseIf e.Button.Text = "Button3" Then
            MsgBox("You clicked button 3...")
        End If
    End Sub

Try it and maybe you like it!

Daniël
0
 
LVL 1

Expert Comment

by:Trancedified
ID: 11855900
Hello,

This references the index of each button in the toolbar that you made:

Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick
        Select Case ToolBar1.Buttons.IndexOf(e.Button)
            Case 0
                 'skip this one
            Case 1
                'code for 1st button
            Case 2
                'More code here for other buttons
            Case 3 'etc etc
        End Select
    End Sub

Good luck

Chris
0
 
LVL 7

Author Comment

by:davidrichardson
ID: 11856846
sorry i thought i closed this question
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now