计时器不在this.Controls中,如何找到它们? [英] Timers are not in this.Controls so how do I find them?

查看:73
本文介绍了计时器不在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.

推荐答案

如果这是Winforms,并且您已经添加了自己的与设计人员一起使用计时器,那么您将在yourForm.components私有成员变量中找到它,而不是在Controls属性中找到它.

看看YourFile.Designer.cs文件,您将在其中找到如何将计时器合并到表单中.

希望对您有所帮助.
If this is Winforms, and you have added your timer with the designer, then you will find it in the yourForm.components private member variable, rather than in Controls property.

Have a look at YourFile.Designer.cs file, you will find in there how your timer is incorporated in your form.

Hope this helps.


您是否尝试了
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中,如何找到它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆