Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
How do you get to the code behing when pressing the enter key on the keyboard eg.when you enter password in the text box then press enter the code for the login button should be executed
Posted 28-Sep-11 4:32am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Well let's say that if will be nicer to have a button in the same form, and then in the form properties set the AcceptButton property to a button that will be activated by pressing enter and the code in the click event will be executed.
 
Actually it is more difficult to explain it than do it. Take a look here for an example
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.acceptbutton.aspx[^]
 
Cheers!
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Add code to handle the KeyPressed event for your text box. In that handler, add code something like:
 
if (e.KeyChar == '\r')
{
    // add your code here

    // set the Handled flag to true
    e.Handled = true;
}
 
Edit: Code Formatted.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

if you want to link button with Enter key press then set that Accept Button property of button control ...
Smile | :)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Just go to the properly window of the form and you will see a property called acceptbutton and if you click on the next colum you will be able to select the login button and this will do the job
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

 
you have to set  "defaultbutton" in form tag  Eg.
 
<form id="form1" runat="server" defaultbutton="ButtonID">
</form>
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 686
1 OriginalGriff 345
2 CPallini 200
3 PIEBALDconsult 150
4 Magic Wonder 131
0 OriginalGriff 5,795
1 Sergey Alexandrovich Kryukov 5,028
2 CPallini 4,700
3 George Jonsson 3,142
4 Gihan Liyanage 2,450


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 1 Oct 2011
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