.NET 4.x Один таймер запускает другой - C#
Формулировка задачи:
Привет.
Помогите сделать двойной таймер.
Есть форма на ней два combobox.
Надо чтобы при нажатии на кнопку запускался 1 таймер, который возьмет значение из combobox1.
А как только он достигнет 0 запускался второй таймер(берущий значение из combobox2).
Сам таймер должен "идти" от заданного время к нулю.
Решение задачи: «.NET 4.x Один таймер запускает другой»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
const int firstConditionValue = 20;
const int secondConditionValue = 10;
const int startCounterValue = 20;
Timer timer;
int timerCounter; //счётчик для таймера
public Form1()
{
InitializeComponent();
timerCounter = startCounterValue;
timer = new Timer();
timer.Interval = 1000;
timer.Tick += new EventHandler(timer_Tick);
}
void timer_Tick(object sender, EventArgs e)
{
if (timerCounter <= firstConditionValue && timerCounter > secondConditionValue)
{
label1.Text = timerCounter.ToString();
}
else if (timerCounter <= secondConditionValue && timerCounter > 0)
{
label2.Text = timerCounter.ToString();
}
else if (timerCounter == 0)
{
timer.Stop();
ResetInfo();
}
timerCounter--;
}
private void btnStart_Click(object sender, EventArgs e)
{
if (!timer.Enabled)
{
btnStart.Text = "Стоп";
timer.Start();
}
else
{
btnStart.Text = "Запуск";
timer.Stop();
ResetInfo();
}
}
private void ResetInfo()
{
timerCounter = startCounterValue;
label1.Text = string.Empty;
label2.Text = string.Empty;
}
private int ToMilliseconds(int minutes)
{
return minutes * 60000; //minutes * 60 * 1000
}
}
}