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

后端 未结 9 1557
长发绾君心
长发绾君心 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:55

    I improved/fixed my extension method.

    public  static class ControlsExtensions
    {
        public static void ClearControls(this Control frm)
        {
            foreach (Control control in frm.Controls)
            {
                if (control is TextBox)
                {
                    control.ResetText();
                }
    
                if (control.Controls.Count > 0)
                {
                    control.ClearControls();
                }
            }
        }
    }
    

提交回复
热议问题