Results 1 to 7 of 7

Thread: [RESOLVED] Reset Button for a textbox

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2009
    Posts
    133

    Resolved [RESOLVED] Reset Button for a textbox

    Can anyone help me write a code for a Reset button to clear all information for a textbox.

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Reset Button for a textbox

    Code:
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            textbox1.text = String.Empty
        End Sub

    where textbox1 is your textbox name, and button1 is the button name.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2009
    Posts
    133

    Re: Reset Button for a textbox

    Thanks, and how could I make the words Reset Button appear in the textbox after I have pressed the reset button

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Reset Button for a textbox

    you would replace string.empty in my example above with "Reset Button"

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Sep 2009
    Posts
    133

    Re: Reset Button for a textbox

    Ok thanks
    Last edited by noreaga_ls; Sep 25th, 2009 at 07:08 PM. Reason: Started another topic

  6. #6
    New Member
    Join Date
    Nov 2017
    Posts
    1

    Re: Reset Button for a textbox

    Quote Originally Posted by noreaga_ls View Post
    Ok thanks

    and if i want to reset multiple textbox?

  7. #7
    Fanatic Member kpmc's Avatar
    Join Date
    Sep 2017
    Posts
    1,012

    Re: Reset Button for a textbox

    Quote Originally Posted by Theunkwon1 View Post
    and if i want to reset multiple textbox?
    So, think about it... If you had a control named Textbox1, and someone showed you how to change the .text property of textbox1, would you not suppose it should be a similar procedure for Textbox2, and os on?

    If you're dealing with mass textboxs you can group them in panels or group box's and iterate them setting them accordingly. Here is an example of "resetting" all textboxs within a Group Box.

    Code:
            For Each Ctrl As Control In GroupBox_CorpInfo.Controls
                If TypeOf Ctrl Is TextBox Then
                    Dim tbox As TextBox = CType(Ctrl, TextBox)
                    tbox.Text = "Reset Button"
                End If
            Next
    This would be similar for any control that has a "Controls collection"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width