首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

请教foreach中怎么传递控件的类型?

2011-12-25 
请问foreach中如何传递控件的类型???在线等!!!我现在把foreach写在一个自定义函数里面,函数体如下所述publ

请问foreach中如何传递控件的类型???在线等!!!
我现在把foreach写在一个自定义函数里面,函数体如下所述

                public   static   void   ForeachCtrl()
                {
                        foreach   (Control   ctrl   in   this.Controls)
                        {
                                if   (ctrl   is   TextBox)
                                {
                                        .....
                                }
                        }
                }

我想在调用这个函数的时候,TextBox这里可以用其他类型来替换,这样子的话,我在主程序地方只要定义我想要遍历的控件类型,这里就能查找出来。。。

不知道这样子说,各位高手能否明白,谢谢!!!

[解决办法]
public static void ForeachCtrl(System.Type t)
{
foreach (Control ctrl in this.Controls)
{
if (typeof(ctrl).FullName==t.FullName)
{
.....
}
}
}
这样应该可以吧
传进控件的typeof(ctrl)
[解决办法]
public static void ForeachCtrl( Type t)
{
foreach (Control ctrl in this.Controls)
{
if (ctrl.GetType() == t )
{
.....
}
}
}

[解决办法]
呵呵 解决了吧
[解决办法]
楼上可以
[解决办法]
学习
[解决办法]

or
public static void ForeachCtrl( System.Web.UI.Control control )
{
foreach (Control ctrl in this.Controls)
{
if (ctrl.GetType() == control.GetType() )
{
.....
}
}
}

热点排行