Timer Control in VB.NET

In this article you will learn how timer control works in VB.NET.
  • 2615
The Timer Control allows you to set specific time intervals until some code has to be executed. Here is how you program the timer control in VB.NET.

Step1:    Open VB.Net and create a new windows application.

Step2:    Add  a listbox to the form. We are going to use the listbox to additems to it every timer control gets executed.

Step3:    Add the timer control to your form. Notice how the timer control is not shown on the form but instead in a different panel at the bottom.

12.gif

           l3.gif

Step4:    Click on the timer control and press the F4 key to bring up the timer's property window , change the timer's enabled property from false to true and also change the timer's interval property to 1000 which is about one second.

Step5:    Double click the timer control to bring up the timer's tick event. In the tick event we are going to add the code:             

Public Class Form1
   Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  ListBox1.Items.Add(ListBox1.Items.Count)
   End Sub

End
Class
                
What this does is add to our listbox the number of items in the listbox each time the tick event executes which we set earlier to 1000 or every second.


Step6:    Run the program by pressing F5 keyword on your keyboard and notice how the numbers get added to the listbox. With the help of the scroll bar you can see the numbers till end. 
timer.gif
 




 timer.gif

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.