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

后端 未结 9 1551
长发绾君心
长发绾君心 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 05:53

    I like lambda :)

     private void ClearTextBoxes()
     {
         Action func = null;
    
         func = (controls) =>
             {
                 foreach (Control control in controls)
                     if (control is TextBox)
                         (control as TextBox).Clear();
                     else
                         func(control.Controls);
             };
    
         func(Controls);
     }
    

    Good luck!

提交回复
热议问题