C# 代码
TextTime.Text = DateTime.Now.ToString();
想要每秒刷新这个文本框
或显示任何想法的数字时钟
C# 代码
TextTime.Text = DateTime.Now.ToString();
想要每秒刷新这个文本框
或显示任何想法的数字时钟
您可以使用DispatcherTimer:
var timer = new DispatcherTimer
{
Interval = TimeSpan.FromSeconds(1.0)
};
timer.Tick += (o, e) =>
{
TextTime.Text = DateTime.Now.ToString();
};
timer.Start();
最简单的方法是向您的应用程序添加一个计时器,并按如下所示进行操作:
表单加载:
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");
}