设计个按键 按键触发定时器
设计个按键 按键触发定时器怎么做?
timer1_Tick += new System.EventHandler(this.timer1_Tick);
private void timer1_Tick(object sender, EventArgs e)
{
int i = 0;
System.Timers.Timer timer1 = new System.Timers.Timer();
timer1.Enabled = false;
timer1.Interval = 50;
timer1.AutoReset = true;
imageList1.Images.Add(Image.FromFile("c:\\1.bmp"));
imageList1.Images.Add(Image.FromFile("c:\\2.bmp"));
p1.Image = imageList1.Images[i++];
}
------解决方案--------------------
何为按键触发定时器?
*可以理解为“启动”定时器;
*可以理解为“执行”时间到达时的程序。
C# code
//方案一
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
//方案二
private void button1_Click(object sender, EventArgs e)
{
timer1_Tick(null,null);
timer1_Tick(sender,e); //这样也可以
}