WPF动态时间(电子表)
Posted 欢迎莅临 SUN WU GANG 的园子!!!
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WPF动态时间(电子表)相关的知识,希望对你有一定的参考价值。
private DispatcherTimer dispatcherTimer; public MainWindow() { InitializeComponent(); dispatcherTimer = new System.Windows.Threading.DispatcherTimer(); // 当间隔时间过去时发生的事件 dispatcherTimer.Tick += new EventHandler(ShowCurrentTime); dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 1); dispatcherTimer.Start(); } public void ShowCurrentTime(object sender, EventArgs e) { //获得星期 //this.tBlockTime.Text = DateTime.Now.ToString("dddd", new System.Globalization.CultureInfo("zh-cn")); //this.tBlockTime.Text += "\\n"; //获得年月日 //this.tBlockTime.Text = DateTime.Now.ToString("yyyy:MM:dd"); //yyyy年MM月dd日 //this.tBlockTime.Text += "\\n"; //获得时分秒 this.tBlockTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss dddd"); }
<TextBlock Name="tBlockTime" FontSize="40" Grid.Column="1" HorizontalAlignment="Right" Foreground="Green"/>
运行效果:
以上是关于WPF动态时间(电子表)的主要内容,如果未能解决你的问题,请参考以下文章