Clear Multiple TextBoxes in C#
If you are a beginner in Programming Languages and you’re using C#.net, this tutorial will help you minimize your codes and lessen your work. This procedure is to clear all the data in the TextBoxes in a certain Form, for example, when you create a “Registration” Form.
To start with:
Open Microsoft Visual Studio and create new Windows Form Application. Then do the following design of a Form as shown below.
After that, go to the Solution Explorer, double click the “View Code” to display the code editor.
Then, create a method for clearing the text in the Textboxes.
private void clearTxt(Control container) { try { //'for each txt as control in this(object).control foreach (Control txt in container.Controls) { //conditioning the txt as control by getting it's type. //the type of txt as control must be textbox. if (txt is TextBox) { //if the object(textbox) is present. The result is, the textbox will be cleared. txt.Text = ""; } } } catch(Exception ex) { MessageBox.Show(ex.Message); } }
Go back to the design view, double click the “Clear” button and do the following codes for calling the method of clearing text.
private void button1_Click(object sender, EventArgs e) { //call a method for clearing all text in the textbox clearTxt(this); }
Output:
For all students who need programmer for your thesis system or anyone who needs a sourcecode in any programming languages. You can contact me @ :
Email – [email protected]
Mobile No. – 09305235027 – tnt
You really make it seem really easy with your presentation but I find this matter to be really one thing which I feel I might by no means understand. It kind of feels too complex and extremely broad for me. I am looking forward for your next submit, I’ll try to get the hold of it!
It is not my first time to pay a visit this site, i am visiting this website dailly and take nice information from here all the time.