http://blog.joycode.com/ghj/posts/15093.aspx

解决方案 »

  1.   

    public void ClearControl(Form form)
        Control ct1, com1;
        DevExpress.XtraEditors.TextEdit txtTmp;
        DevExpress.XtraEditors.ComboBox cbTmp;
        GroupBox grpTmp;
        foreach(ct1 in form.Controls)
        {
            if(TypeOf(ct1)==TypeOf(txtTmp))
                ct1.Text = ""
            if(TypeOf(ct1)==TypeOf(cbTmp))
                ct1.Text = ""
            if(TypeOf(ct1)==TypeOf(grpTmp))
            {
               foreach(com1 in ct1.Controls)
               {
                  if(TypeOf(ct1)==TypeOf(txtTmp))
                    ct1.Text = ""
                  if(TypeOf(ct1)==TypeOf(cbTmp))
                    ct1.Text = ""
               }
            }
        }
    }
      

  2.   

    public void ClearControl(Form form)
    {
       Control ctl,coml;
      foreach(Control in form.Controls)
      { 
         if(ctl.GetType() == TextBox)
         {
           ctl.Text = "";
          }
         else if(ctl.GetType() == ComboBox)
        {
          ctl.Text = "";
         }
         else if(ctl.GetType() == GroupBox)
        {
           foreach(Control coml in ctl.Controls)
          {
            if(coml.GetType() == TextBox)
            {
              coml.Text = "";
            }
             else if(coml.GetType() == ComboBox)
            {
                  coml.Text = "";
               }
    }
    }}
    }
      

  3.   

    public void ClearControl(Form form){
    Control ct1, com1;
    foreach (ct1 in form.Controls) {
    if (ct1 is DevExpress.XtraEditors.TextEdit) {
    ct1.Text = "";
    }
    if (ct1 is DevExpress.XtraEditors.ComboBox){
    ct1.Text = "";
    } if (ct1 is GroupBox) {
    foreach (com1 in ct1.Controls) {
    if (com1 is DevExpress.XtraEditors.TextEdit) {
    com1.Text = "";
    }
    if (com1 is DevExpress.XtraEditors.ComboBox){
    com1.Text = "";
    }
    }
    }
    }
    }
      

  4.   

    照楼上的定提示错误:“E:\TaiTungBox\TaiTungBox\PublicClass.cs(27): 在 foreach 语句中,类型和标识符都是必需的‘
      

  5.   

    不好意思,犯了个错误:
    public void ClearControl(Form form){
    foreach (Control ct1 in form.Controls) {
    if (ct1 is DevExpress.XtraEditors.TextEdit) {
    ct1.Text = "";
    }
    if (ct1 is DevExpress.XtraEditors.ComboBox){
    ct1.Text = "";
    } if (ct1 is GroupBox) {
    foreach (Control com1 in ct1.Controls) {
    if (com1 is DevExpress.XtraEditors.TextEdit) {
    com1.Text = "";
    }
    if (com1 is DevExpress.XtraEditors.ComboBox){
    com1.Text = "";
    }
    }
    }
    }
    }