Click here to Skip to main content
15,879,348 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
I use following code to do a simple animation. But I want to use an button (when pressing it) to stop the animation when the pictureBox is still moving.

So, how I can do it?

Thanks.



VB
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
               Dim t As Integer
        t = 0
        For t = 1 To 80

                Me.PictureBox1.Refresh()
                Me.PictureBox1.Top = Me.PictureBox1.Top - 1
                System.Threading.Thread.Sleep(300)

        Next t
        Timer1.Enabled = False
    End Sub
Posted

1 solution

Why do you coded it that way?
You could show just the next animation frame in the timer tick event (that is the animation is provided by showing a frame per timer tick).
This way stopping it would be trivial.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900