Solved

Toolbar Problem

Posted on 2004-08-16
5
233 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

621 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