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
- Create New Project on Visual Studio
- Select language C#
- Now Select the Windows Application
- Now Select the Timer Tool from tool box and drag it on the form
- Now you have to select an event to start Timer and to stop Timer
- For example I m using it in my form load event. private void Form1_Load(object sender, EventArgs e)
{
timer1.Enabled = true;
}
timer1 is the Timer tool that we dragged. - Declare a global variable of type Integer and initials with 0 int timer = 0; //timer is my variable to count tick of clock
- Now go the Timer tick event and set the what ever you want to do. Right now I m just show it in Label. private void timer1_Tick(object sender, EventArgs e)
{
if (timer == 100)
timer1.Enabled = false;
label1.Text = timer.ToString();
timer++;
}
- That’s it. Now you can apply Timer Control where ever you want to use it.
- To increase or decrease the Interval time check the Interval property. Initially it set to the 100 milliseconds.
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