foreach (Control myControl in this.grpRole.Controls )
{
if (myControl.GetType()==this.chk1.GetType())
{
((CheckBox)myControl).Checked=false;
}
}
这个是遍历的。得到类型我不会阿。。

解决方案 »

  1.   

    foreach (Control conSel in this.Controls)
    {
    if (conSel is TextBox) 
    {
    ////...
    }
    else if (conSel is DateTimePicker)
    {
    ////...
    }
    ....
    }
      

  2.   

    是不是可以这样:
    ComponentCollection components = this.Components;
    foreach (Component NextComponent in components)
    {
        Type myType = NextComponent.GetType();
        //进行处理
    }
      

  3.   

    应该修正一下
    foreach (Component NextComponent in this.components.Components)
    {
        Type myType = NextComponent.GetType();
        //进行处理
    }
    其中components是在form中声明的一个IContainer对象