hi! ok i have a search engine. it works fine. only thing is that when i write something in the textbos i must click the button 'Search' with my mouse for it to start searching. what i want to do is write something to the textbox and hit the 'Enter' key and then start searching.

i searched the forum and i only found this


Private Sub TextBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
If e.KeyCode = Keys.Return Then
keyPressed()
End If
End Sub


Sub keyPressed()
MsgBox("Enter key Pressed.")
End Sub

but i didn't undertand it much... :S

any help would be welcome!! thanks!!!

Recommended Answers

All 6 Replies

Does it work?

i can't make it work....

Try using the KeyDown event instead of KeyUp.

ok i made it work with this:

Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
        If e.KeyCode = Keys.Enter Then
            MsgBox("Help!!!")
        End If
    End Sub

now i have another question. i have this for example :

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim st As String
st = TextBox1.Text
End Sub

and i want to use the 'st' on the first code above without using dim again. is there any way??

Declare "st" outside the Sub

you can simply set the AcceptButton property of the form to the search button

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.