日期:2014-05-17 浏览次数:21137 次
for(int i=0;i<10;i++) { this.label1.Text = i.ToString(); }
private delegate void SetLabelDelegate(DateTime dt); private void button2_Click(object sender, EventArgs e) { Thread th = new Thread(ShowCurrentTime); th.Start(); } private void ShowCurrentTime() { while (true) { SetLabelValue(DateTime.Now); Thread.Sleep(1000); } } private void SetLabelValue(DateTime dt) { if (this.InvokeRequired) { this.Invoke(new SetLabelDelegate(SetLabelValue), new object[] { dt }); } else { this.label1.Text = dt.ToString(); } }