vb.net倒计时 [英] vb.net countdown

查看:92
本文介绍了vb.net倒计时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的一个项目中,一个游戏,我需要显示一个倒计时:3 ... 2 ... 1 ...开始!

In one of my projects, a game, i need to display a countdown: 3... 2... 1... Start!

我在表单上放置了一个标签,没有文本.现在,我想更改文本,等待一秒钟,然后再次更改,依此类推.

I've placed a label on my form, with no text. Now i want to change the text, wait for one second, then change it again, and so on.

我不想使用timer.tick事件,因为我已经有几个计时器,即使我正确命名它也会变得非常混乱.

I don't want to use timer.tick event, because i already have several timers, and it'll get very confusing, even if i name it properly.

我需要使用threading.thead.sleep.

I need to use threading.thead.sleep.

我当前遇到的问题是等待3秒钟,将文本更改为开始!",然后再过一秒钟,它将继续执行我的程序.为什么它不显示其他3条消息?

the problem with what i currently have is it waits 3 seconds, changes the text to 'Start!', and then after another second, it continues my program. Why does it not display the other 3 messages?

我尝试使用文本框并更改文本.同样的结果.我试过几个标签,一个在另一个标签上,并使用label1.hide()和label1.show().结果相同.

I have tried using a textbox, and changing the text. same result. i've tried several labels, one on top of the other, and using label1.hide() and label1.show(). same result.

我该怎么做?

Label1.Text = "3..." Threading.Thread.Sleep(1000) Label1.Text = "2..." Threading.Thread.Sleep(1000) Label1.Text = "1..." Threading.Thread.Sleep(1000) Label1.Text = "Start!"

Threading.Thread.Sleep(1000)





推荐答案

尝试添加Label1.在设置了Labels文本的每一行之后刷新,然后再次使线程休眠.
Try adding Label1.Refresh after each line where the Labels text is set prior to sleeping the thread again.


这篇关于vb.net倒计时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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