Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
does any one can help me in this problem: I have 2 timers in a form C#, I want this: when form is loaded, one timer to start counting down from 15 to 0, after first timer finished, then the second timer start same. I write code but when the form is loaded both timer starts.


What I have tried:

in a form_load:
timer1.Interval = 1000;
           timer2.Interval = 1000;
           timer1.Start();
           timer2.Start();


timer one:
time--;
            if (time== 0)

                timer1.Stop();
            
                lblKoha.Text = koha.ToString();

timer two
time2--;

               if (time2== 0)

                   timer2.Stop();


I declare:
private int time= 15;
        private int time2= 15;
Posted
Updated 1-Mar-17 2:01am

Hello:
In the load you have:
timer1.Interval = 1000;
            timer2.Interval = 1000;
            timer1.Start();           
            timer2.Start();

that is: you start the two timer at the same time.
If you only want to start the timer2 when then timer1 finish in the load you have to suppress the timer2.Start(), and in the timer1 change
if (time== 0)

               timer1.Stop();

for
 if (time== 0) {
                timer1.Stop();
                timer2.Start();
}
 
Share this answer
 
Comments
h5h5 1-Mar-17 8:12am    
thnx man :)
Member 7870345 1-Mar-17 8:22am    
You are wellcome!
C#
timer1.Interval = 1000;
timer2.Interval = 1000;
timer1.Start();           
//timer2.Start();


C#
time--;
if (time== 0)
{
    timer1.Stop();
    timer2.Start();
}
lblKoha.Text = koha.ToString();
 
Share this answer
 
Comments
h5h5 1-Mar-17 8:12am    
thnx so much!
Graeme_Grant 1-Mar-17 8:14am    
you're welcome. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900