C# -NumericupDownをインターバルとして使用したカウントダウンタイマー
質問
これは以前に尋ねられたと確信していますが、機能する解決策を見つけることができないようです。私のフォームには、タイマーとボタンとともにラベルに数字があります。ボタンが押されたときにタイマーを起動し、タイマーがnumericupdownの間隔を等しくし、ラベルにカウントダウンが表示されるようにしたいと思います。私はこれが簡単でなければならないことを知っています。何か助けがありますか?
ここのところ:
int tik = Convert.ToInt32(TimerInterval.Value);
if (tik >= 0)
{
TimerCount.Text = (tik--).ToString();
}
else
{
TimerCount.Text = "Out of Time";
}
タイマーがカチカチするにつれて更新されないようです。
解決
これがあなたが探しているものの簡単な例です。これはあなたが何をする必要があるかについての基本的なアイデアを与えるはずです
//class variable
private int totNumOfSec;
//set the event for the tick
//and the interval each second
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Interval = 1000;
private void button1_Click(object sender, EventArgs e)
{
totNumOfSec = (int)this.numericUpDown1.Value;
timer1.Start();
}
void timer1_Tick(object sender, EventArgs e)
{
//check the timer tick
totNumOfSec--;
if (totNumOfSec == 0)
{
//do capture
MessageBox.Show("Captured");
timer1.Stop();
}
else
label1.Text = "Caputring in " + totNumOfSec.ToString();
}
所属していません StackOverflow