How to clear the text of all textBoxes in the form?

后端 未结 9 1556
长发绾君心
长发绾君心 2020-11-27 05:15
private void CleanForm()
{
    foreach (var c in this.Controls)
    {
        if (c is TextBox)
        {
            ((TextBox)c).Text = String.Empty;
        }
            


        
9条回答
  •  情书的邮戳
    2020-11-27 06:00

    private void CleanForm(Control ctrl)
    {
        foreach (var c in ctrl.Controls)
        {
            if (c is TextBox)
            {
                ((TextBox)c).Text = String.Empty;
            }
    
            if( c.Controls.Count > 0)
            {
               CleanForm(c);
            }
        }
    }
    

    When you initially call ClearForm, pass in this, or Page (I assume that is what 'this' is).

提交回复
热议问题