码迷,mamicode.com
首页 > Windows程序 > 详细

WPF动态时间(电子表)

时间:2017-07-28 19:18:10      阅读:247      评论:0      收藏:0      [点我收藏+]

标签:技术分享   ima   info   read   reg   round   timer   images   eve   

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动态时间(电子表)

标签:技术分享   ima   info   read   reg   round   timer   images   eve   

原文地址:http://www.cnblogs.com/YYkun/p/7251755.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!