嗨我正在與Web應用程序與Windows.Forms.Timer。我創建Timer.Tick事件處理程序來處理Timer_Tick,但我不成功。我沒有得到任何錯誤,但我甚至無法得到結果。這是我的代碼Timer.Tick事件處理程序沒有得到事件Timer_Tick定時器
System.Windows.Forms.Timer StopWatchTimer = new System.Windows.Forms.Timer();
Stopwatch sw = new Stopwatch();
public void StopwatchStartBtn_Click(object sender, ImageClickEventArgs e)
{
StopWatchTimer.Enabled = true;
StopWatchTimer.Interval = 1;
StopWatchTimer.Start();
this.StopWatchTimer.Tick += new EventHandler(StopWatchTimer1_Tick);
sw.Start();
}
protected void StopWatchStopBtn_Click(object sender, ImageClickEventArgs e)
{
StopWatchTimer.Stop();
sw.Reset();
StopWatchLbl.Text = "00:00:00:000";
}
public void StopWatchTimer1_Tick(object sender,EventArgs e)
{
TimeSpan elapsed = sw.Elapsed;
StopWatchLbl.Text = string.Format("{0:00}:{1:00}:{2:00}:{3:00}",
Math.Floor(elapsed.TotalHours),
elapsed.Minutes,
elapsed.Seconds,
elapsed.Milliseconds);
}
爲什麼使用WinForms Timer而不是System.Timers.Timer? – 2012-01-05 19:19:53
什麼是StopWatchTimer vs sw? – 2012-01-05 19:21:18
DeviantSeev我相信有答案,但只是爲了驗證StopWatchTimer和SW之間有什麼區別? – user1231231412 2012-01-05 19:21:27