C#定时器的简单应用

在C#中有时间获取函数,能获取当前的时间,但是是静态显示不是动态的,但是在C#中自己有的定时函

数,我们可以用他来完成时间的动态显示。
sa

            Timer timer;//创建一个时间类的变量
            toolStripLabel1.Text = DateTime.Now.ToString();//显示时间	
            timer = new Timer();  //创建一个新的实例化对象
            timer.Interval = 1000; // 1000毫秒 = 1秒   设置时间的间隔属性,在时间结束之后执行timer的tick事件
            timer.Tick += Timer_Tick;
            timer.Start();
        private void Timer_Tick(object sender, EventArgs e)
        {
            toolStripLabel1.Text = DateTime.Now.ToString();
        }

创建一个label,直接引用就能完成了 

你可能感兴趣的:(c#,开发语言)