實現效果:
關鍵知識:(線程的定義)
實現代碼:
private void Form1_Load(object sender, EventArgs e) { Thread show = new Thread(new ThreadStart(showTime));//定義線程委托執行 show.IsBackground = true;//為后台線程 show.Start();//線程啟動 } //持續顯示時間方法 void showTime() { while (true) { label2.Text = //得到時間 DateTime.Now.ToString(); Thread.Sleep(1000);//線程休眠一秒 } }