如何通过按下按钮来停止我的简单动画 [英] How to stop my simple animation by pressing a button

查看:109
本文介绍了如何通过按下按钮来停止我的简单动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.










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

推荐答案

为什么用这种方式编码?

你可以只显示下一个动画帧计时器刻度事件(即通过显示每个计时器刻度的帧来提供动画)。

这样停止它将是微不足道的。
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.


这篇关于如何通过按下按钮来停止我的简单动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆