C#窗体实现时间效果

论坛 期权论坛 脚本     
匿名技术用户   2021-1-6 08:30   32   0

代码如下:


        private void Form1_Load(object sender, EventArgs e)
        {

            _nowtimes();
        }

        private System.Threading.Timer _times;
        private string oldsday = "";

        private void _nowtimes()
        {
            _times = new System.Threading.Timer(new System.Threading.TimerCallback(Ntimes), null, 0, 1000);
            _times.Change(1, 1000);
        }

        private void Ntimes(object state)
        {
            string nows = System.DateTime.Now.ToString("T");
            string dates = System.DateTime.Now.ToString("D");

            this.BeginInvoke(new Action(() =>
            {

                if (oldsday != dates)
                {
                     Label_day.Text = dates;
                    oldsday = dates;
                }
                Label_NowTime.Text = nows.ToString();
            }), null);
        }

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP