Timer Control in VB.NET


Timer Control is used when user wants to perform some task or action continuously at regular interval of time.

Properties of Timer Control


Various Properties of Timer Control are:

Property Name Description
Name It is used to specify name of the Timer Control.
Enabled It is used to determine weather Timer Control will be enabled or not. It has boolean value true or false. Default value is false.
Interval It is used to specify interval in millisecond. Tick event of Timer Control generates after the time which is specified in Interval Property.

Methods of Timer Control


Various Methods of Timer Control are:

Method Name Description
Start This method is used to start the Timer Control.
Stop This method is used to stop the Timer Control.

Events of Timer Control


Various Events of Timer Control are:

Event Name Description
Tick Tick event of the Timer Control fires continuously after the time which is specified in the Inteval property of Timer Control.

     

Example of Timer Control in VB.NET


Design a form as shown below:

Example of Timer Control

Now set Properties of various control as below:

Control Name Property Name Value
Form1 Text Timer Control Demo
Label1 Name lblHour
Label2 Name lblMinute
Label3 Name lblSecond
Button1 Name btnStart
Text Start
Button2 Name btnStop
Text Stop
Timer1 Name Timer1
Enabled true
Interval 1000

Now double click on the Timer Control and write following code in the Tick event of Timer Contro.

lblHour.Text = Now.Hour
lblMinute.Text = Now.Minute
lblSecond.Text = Now.Second

Now double click on the Start Button and write following code in the Click event of Button.

Timer1.Start()

Now double click on the Stop Button and write following code in the Clcik event of Button.

Timer1.Stop()

Download Projects


Download Programs