開發環境:Microsoft Visio Studio 2015
系統:WINDOWS 10
控件說明:1.timer 2.button(一鍵獲取當前系統時間!) 3.label(顯示時間)
實現的效果如下:


完整源代碼:
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.本博客博文均為原創,轉載請注明出處!

