Can Of Code

C# Quick Tip – Painless Logins

Rather simple post this week. When using a login screen there is a feature that people have come to expect including myself.

Once you have entered your username and password which you may of done by using the keyboard and tabbing between the username and password text boxes. The final step would be to press enter as soon as you finish typing the password to be greeted with the next screen. A habit inherited from the web. So how do we do it in a C# WPF Application.

First step is to create a new event handler for the KeyUp Event of the password text box. In the event handler we want to do the following:

private void passwordTxt_KeyUp(object sender, KeyEventArgs e)
     if (e.Key == Key.Enter)
         login(); // A method that does the login code


To some it up, each time a character is pressed when the password textbox has focus it will check if the key is the Enter key.

Leave a Reply

Your email address will not be published. Required fields are marked *