Search code examples
vb.netbuttonlabelmouseisnumeric

vb.net weird action with mouse button event and label


I have a problem, label1.text need to reach number 5 with the mouse left button clicking on label8 to make, a tool strip menu item appear, but even if is 5 it keep invisible except for clicking one time with the mouse right button. This is the code:

 Private Sub Label8_Click(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Label8.Click
        If e.Button = Windows.Forms.MouseButtons.Left Then
            Label1.Text = Val(Label1.Text) + 1
        Else
            If IsNumeric(Label1.Text = 5) Then
                CustomizeModeToolStripMenuItem.Visible = True
            End If
        End If
End Sub

Solution

  • UPDATE:

    Private Sub Label8_Click(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Label8.Click
                If e.Button = Windows.Forms.MouseButtons.Left And  (Label1.Text <> "5") Then
                    Label1.Text = Val(Label1.Text) + 1
                ElseIf  (Label1.Text = "5") Then
                        CustomizeModeToolStripMenuItem.Visible = True
                End If
        End Sub
    

    Problem you had was to reach this:

    Else
                If IsNumeric(Label1.Text = 5) Then
                    CustomizeModeToolStripMenuItem.Visible = True
                End If
            End If
    

    You needed to right click since if statement took all left clicks. I didn't test it so if something doesn't work say it and i will fix it.