I'm trying to create an animation when clicking a button by using a timer. Here's my code:
Private Sub Animate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Animate.Click
Timer.Enabled = True
End Sub
Private Sub Timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer.Tick
Dim m As Integer = 0
m = m + 1
Select Case m
Case 1
Me.Arrow4.Visible = True
Me.Arrow5.Visible = True
Me.Arrow6.Visible = True
Case 2
Me.Arrow1.Visible = True
Me.Label1.Visible = True
Me.Arrow4.Visible = False
Me.Arrow5.Visible = False
Me.Arrow6.Visible = False
Case 3
Me.Arrow2.Visible = True
Me.Label2.Visible = True
Me.Arrow1.Visible = False
Me.Label1.Visible = False
Case 4
Me.Arrow3.Visible = True
Me.Label3.Visible = True
Me.Arrow2.Visible = False
Me.Label2.Visible = False
End Select
End Sub
The first case shows, but not the rest of it. I set the interval for the timer at 1.
Thanks!
The rest of the cases will never show because you are always instantiating m
to 0 within the scope of the timer's method. m
will always be 1 when the case statement is hit. You'll need to move m
outside the scope of the timer at a class level if you want to persist the value. Just don't forget to set m
back to 0 when you hit your last case. e.g.
...
Case 4
Me.Arrow3.Visible = True
Me.Label3.Visible = True
Me.Arrow2.Visible = False
Me.Label2.Visible = False
m = 0
...