0

我想在 UI 上显示计时器,以便当应用程序星执行计时器从 00:00:00 开始并且当它完成时它的执行计时器停止。计时器应在运行时显示每秒计时。

4

1 回答 1

0

您可以使用 System.Windows.Forms.Timer,它是为像您这样的场景创建的。您可以在MSDN中了解更多信息。

您应该使用以下代码片段作为示例:

Timer timer = new Timer();
timer.Interval = 1000;
timer.Tick += new System.EventHandler(timer_Tick);
timer.Start();

private void timer_Tick(object sender, System.EventArgs e)
{
    this.Text = string.Format("{0:hh:MM:ss}", DateTime.Now);
}

请注意,您应该在不需要时丢弃 Timer。

于 2013-02-21T08:37:32.343 回答