定时器的用法

来源:百度知道 编辑:UC知道 时间:2024/05/31 05:01:05
我打算每隔50毫秒就让int a=a+1,直到Button1按下为止。

按下Button2后,int a 从0开始,每隔50毫秒a++,直到Button1按下。

该怎么编这个程?我不会用计时器

定义一个变量a,添加一个timer,把interval设置为50
我这个是button1开始计时,button2停止计时并显示a的值
没有清空timer,可以自己修改
private void timer1_Tick(object sender, EventArgs e)
{
a = a + 1;
}

private void button1_Click_1(object sender, EventArgs e)
{
timer1.Start();
}

private void button2_Click(object sender, EventArgs e)
{
timer1.Stop();
button2.Text = a.ToString();
}

上面的方法可行··