Toolbar with Case Statement

Jay1b

Contributor
Joined
Aug 3, 2003
Messages
640
Location
Kent, Uk.
I am trying to read the activation of toolbar button using a case
statement. I can read them fine using if statements, but tht seems unefficient.

The problem is, i keep getting a blue line under the is.

Visual Basic:
    Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick

        select e.Button is
            Case tbrOptions

            Case tbrConnect

            Case tbrPause

            Case tbrExit
        End Select

    End Sub

Thanks.
 
You would have to do this:
Visual Basic:
Select Case ToolBar1.Buttons.IndexOf(e.Button)
This will return to you the index of the button, and you then choose what to do based on the index.
 
You can use an If..EndIf block in this way.
Visual Basic:
If e.Button Is tbrOptions Then
  'Blah
ElseIf e.Button is tbrConnect Them
  'Blah
  'etc
End If
Not much different than a Select Case statement. This way you can reorder them without messing up the indexes.
 
Yeah i used the elseif statements when i couldnt figure out the case statements. I made the post, so i could see where i was going wrong.

Thanks again
 
Back
Top