TensE
TensE

Reputation: 49

VB.NET realtime clock in a textbox

How can I make it so that when I load the form a textbox will show me (dd/mm/yyy hh:mm:ss) format clock that is actually moving and is synced with the system?

I tried googling it but so far couldn't find anything that works. Most answers dealt with making labels into clocks but I figured it's the same with textboxes and tried doing what they said with no results. It shows me the time but it's just the time when the form loaded not an actual moving clock. I think most of the answers I found on google are dealing with older versions of VB that's why I can't get it to work.

P.S. I'm just learning coding so the simpler the code the better. Many step by step (like I'm 5) comments are appreciated as well. Thank You

Upvotes: 1

Views: 40731

Answers (2)

Reu Roo
Reu Roo

Reputation: 141

Try to put your time and date string inside a timer. this is how it looks like:

Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick

    TimerText.Text = TimeString
    DaterText.Text = DateString

End Sub

It will surely show you a moving/real time clock that was sync to your computer. :)

Upvotes: 1

Malcolm Salvador
Malcolm Salvador

Reputation: 1566

Add a Timer to your form, and add this code to it's tick event.

 Textbox1.text = Format(Now, "yyyy-MM-dd hh:mm:ss")

You now have a textbox which tells you the current date and time. Don't forget to enable your timer, though!

Upvotes: 1

Related Questions