日期:2014-05-17  浏览次数:20604 次

求教关于批量调用控件方法问题。
各位工程师好:
    我用c#写了一个控件,里面有一个方法 public void DataMonitor()
    在窗口程序中大量使用了该控件,对每一个控件都要使用.DataMonitor方法。可是如果用foreach(control ctrl in this.controls)的话只能调用控件的公共方法,请问怎么才能批量的调用所有该控件的.DataMonitor方法。

    谢谢!

------解决方案--------------------
foreach (你的控件类型 ctrl in this.Controls.OfType<你的控件类型>())
------解决方案--------------------
 foreach (var item in this.Controls)
            {
                if (item.GetType()==typeof("你控件的类型"))
                {
                    控件的.DataMonitor方法
                }
            }