In this blog we will know how to clear the text boxes values in windows application.


Method-1

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

namespace Clear_textbox_windows

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

CleartextBoxes1();

}

public void CleartextBoxes1()

{

foreach (Control Cleartext in this.Controls)

{

if (Cleartext is TextBox)

{

((TextBox)Cleartext).Text = string.Empty;

}

}

}

}

}

Method-2

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

namespace Clear_textbox_windows

{

public partial class Form2 : Form

{

public Form2()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

CleartextBoxes2();

}

public void CleartextBoxes2()

{

for (int i = 0; i < this.Controls.Count; i++)

{

if (this.Controls[i] is TextBox)

{

this.Controls[i].Text = "";

}

}

}

}

}