Timer _timer = new Timer(); DateTime _remainingTime = new DateTime(0); DateTime _timeLoop = new DateTime(0); int _loopCount = 1; public Form1() { InitializeComponent(); _timeLoop = _timeLoop.AddSeconds(10); // chaque boucle de 10 secondes _timer.Interval = 1000; _timer.Tick += new EventHandler(timer_Tick); } //Boutton de lancement private void button3_Click(object sender, EventArgs e) { _remainingTime = _timeLoop; textBox2.Text = string.Format("Boucle N°{0}", _loopCount); textBox1.Text = _remainingTime.ToString("HH:mm:ss"); _timer.Start(); } //Procedure du timer void timer_Tick(object sender, EventArgs e) { if (_remainingTime == new DateTime(0)) { // une boucle vient de finir, if (_loopCount == 3) { textBox2.Text = "Perdu"; _timer.Stop(); } else { // on réinitialize pour la prochaine // attention si tu as un traitement un peu long, arrete et redemarre le timer _timer.Stop(); //ici un traitment long, genre message box ... _timer.Start(); _loopCount++; textBox2.Text = string.Format("Boucle N°{0}", _loopCount); _remainingTime = _timeLoop; } } else _remainingTime = _remainingTime.AddSeconds(-1); textBox1.Text = _remainingTime.ToString("HH:mm:ss"); }
private void timer1_Tick(object sender, EventArgs e) { dt = dt.AddSeconds(-1); labTemps.Text = dt.ToLongTimeString().ToString(); }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question