winform中计数器的实现

步骤:

1)新建工程

2)在窗体上放置一个Label控件,命名为lblClock。并设置以下属性

this.lblClock.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;

this.lblClock.Name = "lblClock";

this.lblClock.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;

this.lblClock.AutoSize = false;

3)在窗体上放置一个Timer控件,该控件可以在Component组件页中找到。并设定以下属性

this.timer1.Enabled = true;

this.timer1.Interval = 1000;

4)双击Timer控件,编写timer1_Tick事件

private void timer1_Tick(object sender, EventArgs e)

{

lblClock.Text = DateTime.Now.ToLongTimeString();

}

程序解释:Timer控件的Interval属性指时间间隔。每隔一个Interval长度的时间,Timer控件的Tick事件就触发一次。要注意,Timer控件只有唯一的一个事件Tick。

 

posted @ 2016-11-16 16:55  水墨晨诗  阅读(721)  评论(0)    收藏  举报