Reset all Text in TextBox on form by using simple code.


Using this simple code we can reset all TextBox on form. In this code i use For Each Loop for select each TextBox on Form. I declare one variable as control then i use loop and i also use TypeOf Operator which are used to define type of variable. TypeOf Operator.

1) Place TexBox on Form.
2) Place Two Button (Reset and Close).
Using this simple code we can reset all TextBox on form.
In this code i use For Each Loop for select each TextBox on Form.
I declare one variable as control then i use loop and i also use TypeOf Operator which are used to define type of variable.
TypeOf Operator.

Form1


Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim contrl As Control
For Each contrl In Me.Controls
If TypeOf contrl Is TextBox Then
contrl.Text = ""
End If
Next
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
End Sub
End Class



Source Code.


Comments

Guest Author: Shourya22 Jan 2013

Hello There,

Very nice code but i don't know vb
so any one can convert this into c#

Thanks and Regards,
Shourya V. sengar

Guest Author: China Babu Boina29 Jan 2013

Hi Shourya V. sengar: from above example replace loop as

foreach(Control i in Me.Controls)
{
if(i == textbox)
i.text="";
}



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: