Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enter key triggering the Login button

Tags:

c#

winforms

My login form has 4 controls. The user can input name, password and enter on button for login.

I'd like the Enter key to trigger the Login action after the Name and Password textboxes are filled out.

How can this be done? Trying to avoid btnLogin.Focus() under the TextBox event.

screen

like image 238
shamim Avatar asked Mar 07 '11 04:03

shamim


People also ask

How do you trigger a button on a Enter key?

To trigger a click button on ENTER key, We can use any of the keyup(), keydown() and keypress() events of jQuery. keyup(): This event occurs when a keyboard key is released. The method either triggers the keyup event, or to run a function when a keyup event occurs.

How do you trigger HTML button when you press Enter?

HTML Press the enter key inside the textbox to activate the button. Show activity on this post. By default, browsers will interpret Enter as submitting a form. <button> by default is type "submit" and accesses whatever is located in the form's action attribute (overridden if button's formaction is present).

How can you avoid button click event when Enter key is pressed in a text box?

Solution 1function (event) { if (event. which == 13 || event. keyCode == 13) { //code to execute here return false; } return true; }); Implement it according to your need.


3 Answers

On your form you can set the AcceptButton property to the login button.

like image 155
Josh M. Avatar answered Oct 17 '22 17:10

Josh M.


Set the form's AcceptButton property to be the Login button. When the user hits Enter, the Click event for that button will be triggered. The CancelButton property is the one you want for your Cancel button.

Again, these are properties of the Form, not the buttons.

like image 45
kprobst Avatar answered Oct 17 '22 15:10

kprobst


    private void txtCost_KeyUp(object sender, KeyEventArgs e)
    {
        //MessageBox.Show(Convert.ToString(e.KeyValue));

            if (e.KeyValue == 13)
            {
                command;
            }
    }
like image 43
Em Saikamnor Avatar answered Oct 17 '22 17:10

Em Saikamnor