Click here to Skip to main content
15,911,715 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
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....
Posted
Updated 23-Mar-12 15:36pm
v2
Comments
ZurdoDev 23-Mar-12 10:14am    
A timer would work. Please share your code and what did not work.
Shahin Khorshidnia 23-Mar-12 10:32am    
Improve your question and copy your code here
Sergey Alexandrovich Kryukov 23-Mar-12 11:59am    
If depends on the UI library. Please tag it. WPF, Forms? Anything else?
The timer works. The question is, which one to use. There are at least three timer types, you can use any of them. Or find out by yourself, code it and ask a question if you face a problem.

Already faced a problem? How about a (short!) code sample?
--SA

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)

C#
 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
 
Share this answer
 
v2
Comments
Shahin Khorshidnia 23-Mar-12 21:47pm    
1. Would you explain about the reason of using a static Timer?
2. OP has strongly specified that Timer in VB(!).
3. Why " myTimer.Tick += new EventHandler" in every btClick?
4. Hungarian notation is not standard. You used it for the name of the control (lbltext). ofCouse a wrong Hungarian notation! (lblText is correct)

For these reasons, I prefer to vote 2
But It is likely that if you improve the solution, I will revote.
Dhanamanikandan 25-Mar-12 13:02pm    
I have updated my solution.. Plz look
Shahin Khorshidnia 25-Mar-12 13:52pm    
1. I don't realy know, why you stick to static(shared) timer?
2. Thank you!
3. Thank you!
4. There is still Hungarian notation. Hungarian is back in the days of VB6
5. Complicated code! it looks like to hard code .
And my revoting:
You fixed 2 problems, then my vote is +3
You need to start your Timer by using code Timer.Start(). Check here[^].
 
Share this answer
 
Comments
prabhakarcs 13-Dec-15 10:58am    
thank u sir code is perfect working ..

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