这样如何?
foreach( Control c in this.Controls)
{
if(c.GetType().ToString()=="System.Windows.Forms.TextBox")
{
c.Text="";
}
}

解决方案 »

  1.   

    编一个函数会比较方便一点;或者:
    TextBox1.Text = TextBox2.Text = TextBox3.Text = ... = "";可能把所有的TextBox加到一个数组会做更多的事情:)----  个人意见
      

  2.   

    告诉你个更全的,带下拉列表和递归算法的
    if(o.GetType().Name=="TextBox")
    {
    if(((TextBox)o).ReadOnly==false&&((TextBox)o).Enabled==true && ((TextBox)o).Visible == true)
    {
    ((TextBox)o).Text="";
    }
    }
    if(o.GetType().Name=="DropDownList")
    {
    if (((DropDownList)o).Enabled==true && ((DropDownList)o).Visible == true)
    {
    ((DropDownList)o).SelectedIndex=0;
    }
    }
    if(o.Controls.Count>0)
    {
    clearForm(o);
    }
      

  3.   

    chinchy(人民需要人民币)
    的方法在TextBox控件占整个窗体的子控件的
    比例很大的话确实很值得用:)
      

  4.   

    这个问题用vb.net相当好解决,和 chinchy(人民需要人民币)兄的很类似。不过,我在用vb.net的时候,遇到了一个问题,
    就是vs.net搜索控件的顺序是什么?
    如果一些控件在groupbox上,是不是还要写代码继续判断是不是在groupbox里面?我之所以这么问是因为我遇到了类似的问题,控件在某个容器里面,像上面这样的代码就会忽略容器里面的控件。请顺便解决一下,谢谢。
      

  5.   

    如果是web窗体,可以用html控件的reset按钮来解决!