Click here to Skip to main content
15,896,727 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
In a simple windows form application there is 3 textbox and 1 button.

Say a user of program may want to enter a lot of data with this form.
Every time he/she fills the textboxes and press enter button by mouse or after filling last textbox he/she pushes the TAB key in keyboard and pushes the Enter key which is faster than using mouse.
But it is still slow.

Is there an event hander which runs when user fill the 3rd textbox push Enter Key then program save data?


Example: Like google search engine, you enter your phrase in thex box and pushing the Enter key, then searching will be started.

I want this for making my form most user friendly.
I can't recognize the event handler.

Please help
Posted
Updated 6-Apr-11 23:24pm
v3
Comments
Dalek Dave 7-Apr-11 5:24am    
Edited for Grammar, Syntax and Readability.

Use the Keypress event of the 3rd TextBox. Inside that event handler all you have to do is to check if the user pressed the enter button and then call the routine that saves the data, clears the form and jumps back to the first input field.

Happy coding!
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 1-Apr-11 5:39am    
Good, my 5.

Good morning, Manfred.

Congratulations with congratulations with April 1st! :-)
Din't you see my April 1st post yet?
Please see this (and of course my "Answer"): http://www.codeproject.com/Questions/175233/WARNING-Black-Line-of-Death-in-windows-phone-7.aspx

:-)
--SA
Have your tried catching the 3rd textbox's KeyUp event? The event handler contains information about the key that was pressed!

C#
if (e.KeyCode == KeyCodes.Enter)
{
  // Do stuff!
}


Have fun!

Eduard
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 1-Apr-11 13:50pm    
You artistically avoided answering the question "What is Keyboard Enter Button event handler". After all, let OP learn something on her/his own, this would be much more useful.
My 5.
--SA
Dalek Dave 7-Apr-11 5:25am    
Good Call.
Set the AcceptButton property of form as your button name.
 
Share this answer
 
check this url

http://www.dotnetperls.com/keycode[^]


or use the code

C#
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Enter)
    {
    // Enter (return) was pressed.
    // ... Call a custom method when user presses this key.
    AcceptMethod();
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900