2012-11-13 24 views
1

我想知道如何實現此目標?如何在C#中顯示計時器的刻度值

private void btnProcess_Click(object sender, EventArgs e) 
{ 
    timer1.Start(); 
    //100 plus line of code here 
    timer1.Stop(); 
} 

int i = 0; 

private void timer1_Tick(object sender, EventArgs e) 
{ 
    i++; 
    label1.text = i.toString(); 
} 

我希望發生的是,當我按下按鈕計時器將運行在label1.text顯示時間,它會停止,直到它達到計時器停止功能

+0

不要在按鈕上無條件按下定時器 - 在這種情況下,定時器可能永遠不會啓動*。 (這比這更復雜一點,但實際上需要工作才能讓WinForms時間*在UI線程被阻塞時觸發。) – 2012-11-13 02:08:24

+0

備註:一個小節中的100多行代碼非常糟糕(除非這樣只是一個概念證明......即使如此也很糟糕)。 –

+0

「不起作用」?這是對這個問題的一個可怕的描述。 – spender

回答

3
var sw = Stopwatch.StartNew(); 
//100 lines of code... 
label1.Text = sw.Elapsed.ToString(); 

? ??

+0

謝謝!它的作品^^ –

+0

我可以查看像一個計時器? –

+0

wehn按鈕被點擊標籤會改變像0.01-> 0.02-> 0.03等..直到它完成? –