Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# VS2010
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 31-Mar-11 23:36pm
Edited 7-Apr-11 0:24am
v3
Comments
Dalek Dave at 7-Apr-11 5:24am
   
Edited for Grammar, Syntax and Readability.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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!
  Permalink  
Comments
SAKryukov at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Have your tried catching the 3rd textbox's KeyUp event? The event handler contains information about the key that was pressed!
 
if (e.KeyCode == KeyCodes.Enter)
{
  // Do stuff!
}
 
Have fun!
 
Eduard
  Permalink  
Comments
SAKryukov at 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 at 7-Apr-11 5:25am
   
Good Call.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Set the AcceptButton property of form as your button name.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

check this url
 
http://www.dotnetperls.com/keycode[^]
 

or use the code
 
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();
    }
}
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 365
1 Sergey Alexandrovich Kryukov 319
2 CPallini 275
3 DamithSL 214
4 Maciej Los 185
0 OriginalGriff 5,455
1 DamithSL 4,457
2 Maciej Los 3,885
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,115


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 30 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100