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
Solved

Toolbar Problem

Posted on 2004-08-16
5
230 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

829 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