如何调用一个方法在C#的winform
问题描述:
运行一个函数,每5在C#的winform 自动秒每分钟automactic当程序执行我调用一个方法到负载如何可以把这个代码在C#的winform如何调用一个方法在C#的winform
公共无效InitTimer()
{
timer1 = new Timer();
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Interval = 200; // in milliseconds
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
MessageBox.Show("test");
}
答
更换200至5000
public void InitTimer()
{
timer1 = new Timer();
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Interval = 5000; // in milliseconds => 1 sec = 1000 millisec
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
MessageBox.Show("test");
}
+0
我知道,但我的问题是,我把这种方法像加载等...... –
+0
我不知道你的业务,但我建议在构造函数中使用它' –
答
如果你的视觉工作室工作,在工具箱中拖动一个计时器形式间隔设置为5000,集ENA流血成真。这将自动启动负载计时器,在形式负载使用
timer1.Start();
这将开始在页加载定时器。
但是不是你的代码工作?有一件事你必须改变的是5000(5秒)的时间间隔。但除此之外,我不知道你的疑问是什么 –