本文介绍了计时器不在this.Controls中,如何找到它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想遍历窗体上的所有控件,并存储/检索找到的所有计时器的.Interval值.
我以为可以使用以下代码,但是找不到我的计时器.
I would like to iterate through all the controls on a form and store/retrieve the .Interval values for all the Timers found.
I thought I could use the following code but it does not find my timer.
foreach (Control ctrl in this.Controls)
{
if (ctrl.GetType() == typeof(Timer))
{
MessageBox.Show("Found 1");
}
}
如果不在this.Controls中,我在哪里可以找到这些计时器?我希望我不必在运行时动态添加它们即可拥有它们的集合.
Where would I find these timers if not in this.Controls? I would hope I would not have to dynamically add them at run time in order to have a collection of them.
推荐答案
for (int i = 0; i < this.Controls.Count; i++)
{
if (this.Controls[i].Name.Contains("timer"))
{
MessageBox.Show("Found it's name is ->"+this.Controls[i].Name);
}
}
这篇关于计时器不在this.Controls中,如何找到它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!