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

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

    Maybe you want more simple and short approach. This will clear all TextBoxes too. (Except TextBoxes inside Panel or GroupBox).

     foreach (TextBox textBox in Controls.OfType())
        textBox.Text = "";
    

提交回复
热议问题