如何在vb.net中使用计时器 [英] how use timer in vb.net

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

问题描述

喜。我需要在20秒后将lable1名称更改为Ready,当我点击button1时。我尝试使用timer.but not success.please给我简单的代码或任何advise.please.im使用vb.net

这是我的coad

private sub timer1_timer()

label1.text =loading

end sub

我在解决方案探索中启用我的计时器,它有1000个间隔

谢谢....

hi. i need change lable1 name as "Ready" after 20 second when i click on the button1. im tryed using timer.but not success.please give me simple code or any advise.please.im using vb.net
this is my coad
private sub timer1_timer()
label1.text="loading"
end sub
im enable my timer in solution explore and it have 1000 interval
thanks you....

推荐答案





使用VB查找下面的答案(我已根据Shahin Khorshidnia更新了我的代码)



请创建标签(将名称设为lblText)& 按钮(设置名称为btClick)



Hi,

Find the answer below using VB (I have updated my code as per Shahin Khorshidnia)

Please create label (Set name as lblText) & Button (Set name as btClick)

 Public Class TimerApplication
    Private Shared WithEvents myTimer As New System.Windows.Forms.Timer()
    Private Shared alarmCounter As Integer = 1
    Private Shared exitFlag As Boolean = False

    'This is the method to run when the timer is raised.
    Private Shared Sub TimerEventProcessor(ByVal myObject As Object, _
                                         ByVal myEventArgs As EventArgs) _
                                     Handles myTimer.Tick
        myTimer.Stop()
        exitFlag = True

    End Sub

    'Button click event
    Private Sub btClick_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btClick.Click
        lblText.Text = ""
        myTimer.Interval = 10000
        myTimer.Start()

        ' Runs the timer, and raises the event.
        While exitFlag = False
            ' Processes all the events in the queue.
            Application.DoEvents()
        End While
        'Print the lable value after 10 seconds
        lblText.Text = "Ready"
    End Sub
End Class


你需要开始你的Timer使用代码Timer.Start()。查看此处 [ ^ ]。
You need to start your Timer by using code Timer.Start(). Check here[^].


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

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