如何将参数传递给System.Windows.Forms.Timer
?
private System.Windows.Forms.Timer timer;
timer.Interval = 1000;
timer.Tick += new EventHandler(timer_Tick);
timer.start
private void timer_Tick(object sender, EventArgs e)
{
}
如何传递对象sender
的值?
答案 0 :(得分:6)
简单的计时器代码 - 在间隔时间结束时,无需向任何发送者传递其get调用。
Timer t = new Timer();
t.Interval = 2000;
timer1.Enabled = true;
timer1.Tick += new System.EventHandler(OnTimerEvent);
//You can use Tag property of your timer as userState
void timer1_Tick(object sender, EventArgs e)
{
Timer timer = (Timer)sender;
MyState state = timer.Tag as MyState;
int x = state.Value;
}
答案 1 :(得分:1)
我猜计时器类上有 Tag 属性。