Вот моя кнопка, с которой запускает таймер:
Код: Выделить всё
public partial class _Default : Page
{
int counter = 0;
protected void Page_Load(object sender, EventArgs e)
{}
protected void Button2_Click(object sender, EventArgs e)
{
Timer1.Tick += Timer1_Tick;
Timer1.Interval = 1000; // 1 second
Timer1.Enabled = true;
Label1.Text = counter.ToString();
}
}
Код: Выделить всё
protected void Timer1_Tick(object sender, EventArgs e)
{
counter = 150;
counter--;
if (counter == 0)
{
Timer1.Enabled = false;
}
Label1.Text = counter.ToString();
}
Код: Выделить всё
Я также хочу спросить, могу ли я использовать класс StopWatch в качестве Таймер обратного отсчета, потому что он более точен в секундах, если вы можете привести мне пример...
Подробнее здесь: https://stackoverflow.com/questions/761 ... ops-in-asp
Мобильная версия