C# .NET - timer control display text after certain time interval

Asked By Muthu Kumar on 19-Jun-12 05:10 AM
i have a form with 4 labels.and a timer control. i need each label to display a text after certain time of the time count.




for (ex)




i set the timer control intervel = "20000"
when the intervel time comes to 15000 label1 display on "pls wait for 15 sec"
when the intervel time comes to 10000 label2 display on "pls wait wait for 10 sec"
when the intervel time comes to 5000 label3 display on "pls wait for 5 sec "


when the intervel time comes to 1000 label4 display on "it's almost over"
like this 
Thanks 

S K replied to Muthu Kumar on 19-Jun-12 05:15 AM
You can see these thread for how can timer control are using in asp.net page
http://ajax.net-tutorials.com/controls/timer-control/ 
http://forums.asp.net/t/1085601.aspx 
Chintan Vaghela replied to Muthu Kumar on 19-Jun-12 06:09 AM

Hi Frndz,

 

Functionality:  Timer Tick Display Label Value

 

Set Timer interval 5 sec

 

Now take one Static variable now decrement this static variable value every 5 seconds

 

        COunt = (Convert.ToInt32(COunt) - 5).ToString();

 

 

 

Logic   :

 

 

Timer timer = new Timer();

      static string COunt = "21";

void timer_Tick(object sender, EventArgs e)

      {

 

        COunt = (Convert.ToInt32(COunt) - 5).ToString();

 

        if (COunt == "16")

        {

          label2.Text = "pls wait for 15 sec";

        }

        if (COunt == "11")

        {

          label3.Text = "pls wait for 10 sec";

        }

        if (COunt == "6")

        {

          label4.Text = "pls wait for 5 sec";

        }

        if (COunt == "1")

        {

          label5.Text = "it's almost over";

        }

      }

 

private void Form1_Load(object sender, EventArgs e)

      {

 

        timer.Tick += new EventHandler(timer_Tick); // Everytime timer ticks, timer_Tick will be called

        timer.Interval = (1000) * (5);       // Timer will tick evert 5 seconds

        timer.Enabled = true;             // Enable the timer

        timer.Start();                // Start the timer

 

 

 

 

      }

 

Hope this helpful!

Thanks