1

C# 代码

TextTime.Text = DateTime.Now.ToString();

想要每秒刷新这个文本框

或显示任何想法的数字时钟

4

2 回答 2

5

您可以使用DispatcherTimer

var timer = new DispatcherTimer
{
    Interval = TimeSpan.FromSeconds(1.0)
};
timer.Tick += (o, e) =>
{
    TextTime.Text = DateTime.Now.ToString();
};
timer.Start();
于 2013-02-17T17:10:58.087 回答
3

最简单的方法是向您的应用程序添加一个计时器,并按如下所示进行操作:

 

表单加载:

private void Form1_Load(object sender, EventArgs e) {
   txtdate.Text = DateTime.Now.ToString(("dddd" + ("," + "MM-dd-yyyy")));
   Timer1.Interval = 1000;
   Timer1.Enabled = true;
}

定时器滴答:

private void Timer1_Tick(object sender, EventArgs e) {
   txtTime.Text = DateTime.Now.ToString("HH:mm:ss");
}
于 2013-02-17T17:07:13.707 回答