Amit Phartiyal
Amit Phartiyal

Reputation: 13

Visual Basic 2010 issue in Clearing Text

I am using Visual Basic 2010. I have create a simple Textbox which can take multiline input with three buttons clear Text,Date and Show Message. Assuming the TextBox contains some text. I want to clear the textbox by clicking "Clear Text" button. Button1 is the name of the control "Clear Text" here is the code i used.

        Private Sub Button1_Click()
               Button1.Text = ""
        End Sub

But when i start debugging and click "Clear Text" instead of Textbox getting Cleared the "Clear Text" Control button itself gets Cleared.

Thankyou

Upvotes: 0

Views: 193

Answers (2)

Idle_Mind
Idle_Mind

Reputation: 39152

You can also use the Clear() method:

Clears all the content from the text box.

So that would look like:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    TextBox1.Clear()
End Sub

Upvotes: 0

user5180298
user5180298

Reputation:

because you are clearing the text from button1. replace Button1.Text = "" with textbox1.text="" (textbox1 or the real name of your text box control...)

Upvotes: 2

Related Questions