如何利用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.本博客博文均为原创,转载请注明出处!

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM