2009-10-16 61 views
0

我確信之前已經詢問過這個問題,但似乎找不到可行的解決方案。我的窗體上有一個NumericUpDown,並有一個標籤以及一個計時器和一個按鈕。我希望定時器在按下按鈕時啓動,並且定時器的時間間隔等於NumericUpDown的時間間隔,倒計時將顯示在標籤中。我知道這應該很容易。任何幫助?C# - 使用NumericUpDown作爲區間的倒數計時器

到目前爲止:

int tik = Convert.ToInt32(TimerInterval.Value); 

    if (tik >= 0) 
    { 
     TimerCount.Text = (tik--).ToString(); 
    } 

    else 
    { 
     TimerCount.Text = "Out of Time"; 
    } 

它似乎並沒有更新的計時器滴答聲。

+0

你有什麼具體問題?人們不會爲你寫你的代碼。 –

+0

我寫他的代碼給他,只要它沒有做作業,他就付我 –

+0

不是作業,個人項目。我不喜歡爲人們編寫代碼的想法,我只是被卡住了。我會更新這篇文章以展示我迄今爲止的內容。 – user

回答

2

這是一個快速的例子,你正在尋找什麼。這應該給你一個基本的想法,你需要做什麼

//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(); 
    } 
+0

非常感謝。 – user