こんにちは、私はWebアプリケーションでWindows.Forms.Timerを使用しています。私はTimer_Tickを処理するためにTimer.Tickイベントハンドラを作成しますが、私は成功していません。私は何の誤りもありませんが、結果を得ることはできません。ここに私のコードですTimer.Tickイベントハンドラがイベントを受け取っていませんTimer_Tick in Timer
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);
}
なぜSystem.Timers.Timer'の代わりにWinFormsの 'Timer'を使用していますか? –
StopWatchTimerとswとは何ですか? –
DeviantSeev私は答えがあると思いますが、StopWatchTimerとswの違いは何ですか? – user1231231412