Smart Way to Clear Multiple TextBoxes in C#
Submitted by janobe on Wednesday, April 24, 2019 - 13:47.
In this tutorial, I will teach you how to clear multiple textboxes in c#. This method has the ability to clear all the data inside the textbox in just a click. This is a big help for you when you have multiple textboxes inside the form. Let’s begin.
Download the complete sourcecode and run it on your computer.
For any questions about this article. You can contact me @
Email – [email protected]
Mobile No. – 09305235027 – TNT
Or feel free to comment below
Step 1
Open Microsoft Visual Studio 2015 and create a new windows form application in c#.
Step 2
Do the form just like shown below.
Step 3
Create a method for clearing all data inside the textboxes in the form.- private void clear_all()
- {
- try
- {
- foreach(Control txt in this.Controls)
- {
- {
- txt.Text = "";
- }
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
Step 4
Do the following code to clear all data when the button is clicked.- private void button2_Click(object sender, EventArgs e)
- {
- clear_all();
- }
Add new comment
- 1314 views