Textbox return key event

R

roidy

Is there an event for when the return key is pressed after text has been
entered into a textbox control?

for example I have a textbox and button labeled 'Search', the user enters a
string into the textbox and then presses the search button and a search
function is called. I would also like to just be able to enter text into the
textbox and when the user presses return the search fucntion is called.

The only way I can think of is to use a key down event, but what value for
e.KeyChar is the return key?

Rob
 
R

roidy

Typical 30 seconds after I posted I found the answer.

if e.KeyChar = Chr(13) Then
SearchButton_Click(me, EventArgs.Empty)
End If
 
O

Onur Güzel

Typical 30 seconds after I posted I found the answer.

if e.KeyChar = Chr(13) Then
    SearchButton_Click(me, EventArgs.Empty)
End If

Hi,

Another option could be setting form's AccepButton property to the
button that you want to execute if you press Return key while typing
in textbox. Set the proper button as Form's AcceptButton, and when
user presses Return key, the button's click event will be fired.

HTH,

Onur Güzel
 
R

roidy

Thanks Onur

I had considered that but if you have more that one text box on your form
the event is triggered regardless of which text box you press the return key
in.

Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top