1 Timer time1 = new Timer(); 2 private void time1_Tick(object sender, EventArgs e) 3 { 4 lTime.Text = DateTime.Now.ToString("HH:mm:ss"); 5 } 6 private void XXX_Load(object sender, EventArgs e) 7 { 8 this.time1.Interval = 1000;//一秒 9 this.time1.Tick += new System.EventHandler(this.time1_Tick); 10 this.time1.Start(); 11 }
注解:time1是winfrom的定时器控件,根据在规定时间内,去加载当前是时间,并赋值给lable显示