One Click Textboxes

Bugwee
Posted by in Windows Forms category on for Beginner level | Points: 250 | Views : 7212 red flag
Rating: 3.67 out of 5  
 3 vote(s)

Clear 10 or more textboxes in just one click.


 Download source code for One Click Textboxes

Introduction


In this article I am going to show how to clear 10 or more textboxes in just one click. My example in here I'm just going to show up just 10 textboxes.



Creating the Form

We need to create a form with 10 textboxes and 3 buttons.

Textboxes names:
    Textbox1,TextBox2,...,TextBox10

Button Names:
    btnClearLeft,bntClearRight,btnClear



Clear Left

On btnClearLeft Click Event, put this one
       For Each ctrl As Control In Me.Controls 'For each control on the form.

            If TypeOf ctrl Is TextBox Then 'See if the type is a Textbox.

                Dim idx As Integer = CInt(ctrl.Name.Replace("TextBox", ""))

                If idx >= 1 And idx <= 5 Then
                    CType(ctrl, TextBox).Text = ""
                End If

            End If
       Next 

Result:



Clear Right

On the btnClearRight Click event, put this one
        For Each ctrl As Control In Me.Controls 'For each control on the form.

            If TypeOf ctrl Is TextBox Then 'See if the type is a Textbox.

                Dim idx As Integer = CInt(ctrl.Name.Replace("TextBox", ""))

                If idx >= 6 And idx <= 10 Then
                    CType(ctrl, TextBox).Text = ""
                End If

            End If
        Next

Result:




Clear 1,2,3,9 and 10

On the btnClear event, put this one
       For Each ctrl As Control In Me.Controls 'For each control on the form.

            If TypeOf ctrl Is TextBox Then 'See if the type is a Textbox.
               Dim idx As Integer = CInt(ctrl.Name.Replace("TextBox", ""))
                If idx < 4 Or idx > 8 Then
                    CType(ctrl, TextBox).Text = ""
                End If
            End If

        Next
Result:


Conclusion

This article maybe useful if we have so many textboxes and we need to clear the text on it in just a single click.

Page copy protected against web site content infringement by Copyscape

About the Author

Bugwee
Full Name: Loel Taok
Member Level: Starter
Member Status: Member
Member Since: 11/11/2010 3:29:26 AM
Country: Philippines

http://www.dotnetfunda.com

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)