using Timer = System.Windows.Forms.Timer;
namespace WinFormsApp1
{
public partial class Form1 : Form
{
int a = 0;
public Form1()
{
InitializeComponent();
//定义一个定时器,定时周期为1s
Timer t = new Timer();
t.Interval = 1000;
t.Tick += new EventHandler(timer_Tick);
t.Start();
}
//定时器到时间后,触发该事件
private void timer_Tick(object sender, EventArgs e)
{
a++;
label1.Text = a.ToString(); //把a相加的结果显示在label1控件
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}