定时器控制使用动态控制 [英] Timer control using dynamic control
本文介绍了定时器控制使用动态控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Dynamic中尝试过Timer控件但它会抛出一个错误,因为ConsoleApplicationworking.exe中发生了'System.NullReferenceException'类型的未处理异常
附加信息:对象引用未设置为对象的实例
I have tried Timer control in Dynamic but it throws an error as "An unhandled exception of type 'System.NullReferenceException' occurred in ConsoleApplicationworking.exe"
"Additional information: Object reference not set to an instance of an object"
private Timer Tims;
protected void SetControl()
{
new Timer();
Tims.Tick += new EventHandler(timer1_Tick);
}
private void StartBtn_Click(object sender, EventArgs e)
{
if (Stimer != 0)
{
Tims.Interval = Stimer;
Tims.Enabled = true;
Tims.Start();
}
else
{
MessageBox.Show("Select TimerInterval");
}
}
亲切解决这个问题。
我的尝试:
Kindly solve this problem.
What I have tried:
int Stimer=1000;(From User)
private Timer Tims;
protected void SetControl()
{
new Timer();
Tims.Tick += new EventHandler(timer1_Tick);
}
private void StartBtn_Click(object sender, EventArgs e)
{
if (Stimer != 0)
{
Tims.Interval = Stimer;
Tims.Enabled = true;
Tims.Start();
}
else
{
MessageBox.Show("Select TimerInterval");
}
}
推荐答案
这可能只是一个文书错误。
您的代码是:
This is probably just a clerical error.
Your code is:
new Timer();
而不是:
instead of:
Tims= new Timer();
请阅读RyanDev的评论。
Please read also the comment by RyanDev.
这篇关于定时器控制使用动态控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文