Click here to Skip to main content
14,363,173 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hey,

I have a windows form with C# language and am using vs2010.

I have a username box, password box and button for enter (login).

Now the problem is, if I type the right password in, then I want that if I hit the enter key on my keyboard it automatically hits the enter button btw. automatically logs in without to click on the enter button.

How do I do that?
Posted
Comments
   
What have you tried so far?
—SA
   
I have searched whole google to find the answer of my own, couldn't find anything btw. what gets my problem a answer, and you give me this. (deleted some stupid things I said)
   
We don't accept this kind of talking here.

And it looks so weird, to talk this way to the one who actually provided you with a comprehensively detailed answer, spent time on that, and did something you could easily do by yourself.

Sorry.
—SA

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Handle the event KeyDown (or even KeyUp) of the TextBox with a password:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keydown%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keyup%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.keyeventargs%28v=vs.110%29.aspx[^].

In the event handler code, respond to the key System.Windows.Forms.Enter:
http://msdn.microsoft.com/en-us/library/system.windows.forms.keyeventargs.keycode%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.keys%28v=vs.110%29.aspx[^].

When it is Enter, call the same thing you call on the Click event handler on your "OK" button (or end of modal state of the dialog on OK, if you have any). It would be also good to check up the values of your user name and password field and disable OK and this keyboard action unless they both have some data, non-empty and not containing only blank spaces.

—SA
   
Comments
   
But thanks for this, no code again only sites but ok.
   
You are welcome. Will you accept the answer formally (green "Accept" button)?

You don't need code to solve this simple problem; MSDN documentation has everything to do it; and I gave you exact recipe.

—SA
   
I know, sometimes if I get answers like this then I get a bit strange, sorry for that. But thanks. I tried right now with the KeyDown, but if I hit enter on my keyboard in the passwordbox then it popsup a few times that im logged in btw. if I hit enter the first time it happen nothing but then again then it pops up.
   
Sure. No problem.

(Just a warning: you already got abuse reports on your account, from two different members, which can lead to cancellation of your account if it continues. Most people don't like bad words in posts, as well as wasting time. Nothing personal — I'm here to help, not to scandal.)

—SA
   
It's fine, I have a lot of emails to register a new account, and I use proxys. But I understand, I know sometimes I react different, I will take care of it next time and write a better question btw. search more on google then.
   
This is not fine at all. Please understand it.
—SA

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




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