gpt4 book ai didi

vb.net - 我需要在VB中显示标签之间添加延迟,但是我似乎遇到了麻烦

转载 作者:行者123 更新时间:2023-12-03 13:19:38 26 4
gpt4 key购买 nike

我正在为“fun”创建一个简单的应用程序,在该应用程序中,当用户打开应用程序时,它会假装连接到设备并关闭它。我希望它缓慢显示标签,例如

Connecting to device...
(wait like 10 seconds)
Exploiting registry...
(wait like 10 seconds)

依此类推,从下面的代码中可以看到,我使用了 system.threading.thread.sleep(2000),它可以工作,但会暂停整个代码,并且由于此shutdown.vb是从单独的main.vb中打开的,因此它使整个执行工作变得困惑不堪!除了线程休眠以外,还有其他方法吗?我只需要在每行之间停顿一下,谢谢!代码如下!
Public Class shutdown
Private Sub shutdown_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Label2.Hide()
Label3.Hide()
Label4.Hide()
shutdownConnect()
End Sub
Private Sub shutdownConnect()
Label2.Show()
System.Threading.Thread.Sleep(2000)
Label3.Show()
System.Threading.Thread.Sleep(2000)
Label4.Show()
End Sub
End Class

最佳答案

您可以使用Timer。在设计器中将标签的可见性设置为False,然后使用计时器对其进行更改。

Public Class shutdown
Private counter As Integer
Private Sub shutdown_Load(sender As Object, e As EventArgs) Handles MyBase.Load
timer1.Start()
End Sub
Private Sub timer1_Tick() Handles timer1.Tick
counter += 1
Select Case counter
Case 1
Label2.Visible = True
Case 2
Label3.Visible = True
Case 3
Label4.Visible = True
timer1.Stop()
counter = 0 'reset for next time
End Select
End Sub
End Class

关于vb.net - 我需要在VB中显示标签之间添加延迟,但是我似乎遇到了麻烦,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30519661/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com