系统窗口形成计时器参数

时间:2011-04-21 05:27:12

标签: c# .net timer

如何将参数传递给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的值?

2 个答案:

答案 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;
    }

详细了解这一点:http://www.c-sharpcorner.com/UploadFile/mahesh/WorkingwithTimerControlinCSharp11302005054911AM/WorkingwithTimerControlinCSharp.aspx

答案 1 :(得分:1)

我猜计时器类上有 Tag 属性。