RUoFx
Stealth Master
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 2
1000 XP
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!:
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...
- Private
Sub
Form1_Load(sender As
Object
, e As
EventArgs) Handles MyBase.Load
- Dim
time As
String
= DateTime.Now.ToLongTimeString().ToString()
- End
Sub
Next we set the label text to the time variable's value...
- 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
And finally we start our timer1...
- 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
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...
- 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
Finished!: