How To Use Timer Control In C# Windows Application

This is my second post about the basic controls which we use in C# windows Application. Timer is used to collect the time span of an event to be occurred or to fix certain time span for any event to be occurred or to close any event after certain time. Now its up to you, how you use it.
  




Requirement for the use of timer control is following.

  • Operating System : Windows XP, Windows 7 , Vista
  • Platform :  .Net 2.0 or greater
  • IDE : Visual Studio
  • Language : Csharp
Now Follow the following steps :
  1. Create New Project on Visual Studio
  2. Select language C#
  3. Now Select the Windows Application
  4. Now Select the Timer Tool from tool box and drag it on the form1
  5. Now you have to select an event to start Timer and to stop Timer
  6. For example I m using it in my form load event. 2 private void Form1_Load(object sender, EventArgs e)
           {
               timer1.Enabled = true;
             
           }   
    timer1 is the Timer tool that we dragged.
  7. Declare a global variable of type Integer and initials with 0                                        int timer = 0;   //timer is my variable to count tick of clock
  8. Now go the Timer tick event and set the what ever you want to do. Right now I m just show it in Label. 3                                                                                                                            private void timer1_Tick(object sender, EventArgs e)
           {
               if (timer == 100)
                   timer1.Enabled = false;
               label1.Text = timer.ToString();
               timer++;
           }
  9. That’s it. Now you can apply Timer Control where ever you want to use it. 5
  10. To increase or decrease the Interval time check the Interval property. Initially it set to the 100 milliseconds.
 4
I hope you like it. Don’t forget to give me suggestion what should I write in my next tutorial. If you have any trouble while doing this let me know. Your compliment is valuable for us.

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Powered by Blogger