ToggleButton

I am using this bit of code with a toolbar, my question is how can I get a togglebutton to work with my toolbar?

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
                MsgBox("First Button Clicked")

            Case 1
                MsgBox("ToggleButton On")

            Case 2
                MsgBox("Third Button Clicked")
        End Select
    End Sub

Depending if the togglebutton is on or off it will do this bit of code:

Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        Dim i As Integer
        Dim j As Integer
        Dim output As String
        Try
            ListBox3.Items.Clear()
            For i = 0 To numLines.Value - 1
                For j = 0 To numsPerLine.Value - 1
                    Dim temp As String = IIf(CheckBox1.Checked = True, String.Format("{0:00}", PResults(i, j)), CStr(PResults(i, j)))
                    If output <> "" Then output += " - "
                    output += temp
                Next
                ListBox3.Items.Add(output)
                output = ""
            Next
        Catch
        End Try
    End Sub
teamdadAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonMiddle School Assistant TeacherCommented:
Something like this will work:

    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
                MsgBox("First Button Clicked")

            Case 1
                If ToolBar1.Buttons(1).Pushed Then
                    ' do something if pushed down
                    MsgBox("ToggleButton Down")
                    CheckBox1_CheckedChanged(Nothing, New System.EventArgs)
                Else
                    ' do something else if pushed up
                    MsgBox("ToggleButton Up")
                    CheckBox1_CheckedChanged(Nothing, New System.EventArgs)
                End If

            Case 2
                MsgBox("Third Button Clicked")
        End Select
    End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.