Blog

Clear textboxes values windows

By Satyapriya Nayak Blogs | Windows Controls C# Dec 06, 2012
In this blog we will know how to clear the text boxes values in windows application.
Download Files: Clear textbox window

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 = "";

                }

            }

        }

    }

}

COMMENT USING

PREMIUM SPONSORS

Hire Mobile & Web Developer on demand. 100% satisfaction. Try for 1 week or Money Back. Local and remote developers available all over USA.

Latest Blogs