如何利用C# timer控件实现查看当前系统时间

开发环境:Microsoft Visio Studio 2015

系统:WINDOWS 10

控件说明:1.timer 2.button(一键获取当前系统时间!) 3.label(显示时间)

 

实现的效果如下:

运行结果

如何利用C# <wbr>timer控件实现查看当前系统时间时间跟随系统时间滚动输出

完整源代码:

 1 using System;
 2 using System.Windows.Forms;
 3 
 4 namespace EXP3_53_GetTime
 5 {
 6     public partial class Form1 : Form
 7     {
 8         
 9         public Form1()
10         {
11             InitializeComponent();
12         }
13         bool flag = false;
14         private void button1_Click(object sender, EventArgs e)
15         {
16             flag = true;
17         }
18 
19         private void timer1_Tick(object sender, EventArgs e)
20         {
21             if (flag)
22             {
23                 DateTime time = DateTime.Now;
24                 label1.Text = "当前系统时间为:" + time.ToString();
25             }
26         }
27     }
28 }

 

注:

1.timer控件请谨慎使用,以防程序卡死...

2.本博客博文均为原创,转载请注明出处!

 

posted @ 2016-04-19 22:56  东方之_猪  阅读(5620)  评论(0)    收藏  举报