?
Solved

ToggleButton

Posted on 2004-11-06
1
Medium Priority
?
175 Views
Last Modified: 2010-05-18
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
0
Comment
Question by:teamdad
1 Comment
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 12514679
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

862 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