C# 通过System.Timers.Timer获取时间
2021-05-11 04:29
标签:c# his enabled 设置 als tor set dev orm C# 通过System.Timers.Timer获取时间 标签:c# his enabled 设置 als tor set dev orm 原文地址:http://www.cnblogs.com/shelly0307/p/7592611.html 1 public delegate void timeDelegate();// Timer获取时间
2
3 private void Form1_Load(object sender, EventArgs e)
4 {
5 System.Timers.Timer t = new System.Timers.Timer(1000); //设置时间间隔为5秒
6 t.Elapsed += new System.Timers.ElapsedEventHandler(Timer_TimesUp);
7 t.Enabled = true; //是否触发Elapsed事件
8 t.AutoReset = true; //每到指定时间Elapsed事件是触发一次(false),还是一直触发(true)
9 }
10 private void Timer_TimesUp(object sender, System.Timers.ElapsedEventArgs e)
11 {
12 timeDelegate td = new timeDelegate(timeChange);
13 this.BeginInvoke(td);
14 }
15 public void timeChange()
16 {
17 int hour = System.DateTime.Now.Hour;
18 int minute = System.DateTime.Now.Minute;
19 int second = System.DateTime.Now.Second;
20 textBox1.Text = hour.ToString();
21 textBox2.Text = minute.ToString();
22 textBox3.Text = second.ToString();
23 }
下一篇:乐视云 API
文章标题:C# 通过System.Timers.Timer获取时间
文章链接:http://soscw.com/index.php/essay/84210.html