VB.NET Timer Control

The timer control is a looping control used to repeat any task in a given time interval. It is an important control used in Client-side and Server-side programming, also in Windows Services.

Furthermore, if we want to execute an application after a specific amount of time, we can use the Timer Control. Once the timer is enabled, it generates a tick event handler to perform any defined task in its time interval property. It starts when the start() method of timer control is called, and it repeats the defined task continuously until the timer stops.

Let's create a Timer control in the VB.NET Windows form by using the following steps.

Step 1: Drag and drop the Timer control onto the window form, as shown below.

VB.NET Timer Control

Step 2: Once the Timer is added to the form, we can set various properties of the Timer by clicking on the Timer control.

Timer Control Properties

There are following properties of the VB.NET Timer control.

PropertiesDescription
NameThe Name property is used to set the name of the control.
EnabledThe Enables property is used to enable or disable the timer control. By default, it is True.
IntervalAn Interval property is used to set or obtain the iteration interval in milliseconds to raise the timer control's elapsed event. According to the interval, a timer repeats the task.
AutoResetThe AutoReset property is used to obtain or set a Boolean value that determines whether the timer raises the elapsed event only once.
EventsEvents property are used to get the list of event handler that is associated with Event Component.
CanRaiseEventsIt is used to get a value that represents whether the component can raise an event.

Events of Timer Control

EventsDescription
DisposedWhen control or component is terminated by calling the Dispose method, a Dispose event occurs.
ElapsedWhen the interval elapses in timer control, the Elapsed event has occurred.
TickA tick event is used to repeat the task according to the time set in the Interval property. It is the default event of a timer control that repeats the task between the Start() and Stop() methods.

Methods of Timer Control

MethodsDescription
BeginInt()The BeginInt() method is used to start run time initialization of a timer control used on a form or by another component.
Dispose()The Dispose() method is used to free all resources used by the Timer Control or component.
Dispose(Boolean)It is used to release all resources used by the current Timer control.
Close()The Close() method is used to release the resource used by the Timer Control.
Start()The Start() method is used to begin the Timer control's elapsed event by setting the Enabled property to true.
EndInt()The EndInt() method is used to end the run time initialization of timer control that is used on a form or by another component.
Stop()The Stop() method is used to stop the timer control's elapsed event by setting Enabled property to false.

Let's create a simple program to understand the use of Timer Control in the VB.NET Windows Forms.

TimerProgram.vb

Output:

VB.NET Timer Control

When the program executes, it starts blinking the WELCOME TO JAVATPOINT.COM statement and counting the number to 1, as shown above. When the number is odd, the color of the statement is Red, and when the number is even, the color of the statement is Blue, as shown below.

VB.NET Timer Control




Latest Courses