C# act on enter key in a TextBox

K

kerenx7

Hi!

I have a Textbox and would like to commit a search on the text
entered in it if someone wrote something in and than pressed the Enter
key.

What is the best way to do that?
What event should I use?

Thank you in advance,
Keren
 
D

DSK Chakravarthy

For a windows application, it is recommended to write a keydown event.
For a web application, it is recommended to implement the same with either
validate or lost focus

HTH
 
D

Diego Armando Maradona

in the textbox "keydown" event,

if (e.keycode == keys.return)
{
doSearch();
}
 
I

Ignacio Machin ( .NET/ C# MVP )

Hi!

   I have a Textbox and would like to commit a search on the text
entered in it if someone wrote something in and than pressed the Enter
key.

What is the best way to do that?
What event should I use?

Thank you in advance,
Keren

Take a look at Form.ProcessCmdKey
 

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