Simple Clock in Visual Basic
Submitted by Yorkiebar on Sunday, May 11, 2014 - 12:01.
Introduction:
This tutorial is on how to create a simple clock in Visual Basic.
Design:
For this, we simply need a new Windows Form, with one label - call it; 'clockLbl'. You may center the label to the middle of the form in both x and y axis' and give it a large font size.
We also need a timer, name this timer1. Set it's interval to 1000ms/1second and it's enabled state to 'True'.
Form Load:
On form load, we want to initiate the label with the current computer time. So first we get the current time and store it in to a new 'time' string variable...
Next we set the label text to the time variable's value...
And finally we start our timer1...
Timer 1 Tick:
The final thing we need to do is code our timer 1 tick event. This will simply re-set the text of the label to the now current time of the PC...
Finished!:
- Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- Dim time As String = DateTime.Now.ToLongTimeString().ToString()
- End Sub
- Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- Dim time As String = DateTime.Now.ToLongTimeString().ToString()
- ClockLbl.Text = time
- End Sub
- Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- Dim time As String = DateTime.Now.ToLongTimeString().ToString()
- ClockLbl.Text = time
- timer1.start()
- End Sub
- Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
- Dim time As String = DateTime.Now.ToLongTimeString().ToString()
- ClockLbl.Text = time
- End Sub
Add new comment
- 269 views