如果我在输入密码后按Enter键,如何使密码框工作? [英] How do I get password box working if I hit enter after I fill the password in?

查看:120
本文介绍了如果我在输入密码后按Enter键,如何使密码框工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,



我有一个使用C#语言的Windows窗体并使用vs2010。



我有一个用户名框,密码框和输入(登录)按钮。



现在的问题是,如果我输入正确的密码,那么我想要的是我按下键盘上的回车键,它会自动点击输入按钮顺便说两句。自动登录而不点击输入按钮。



我该怎么办?

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?

推荐答案

处理 TextBox KeyDown (甚至 KeyUp ) >使用密码:

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 [ ^ ]。



在事件处理程序代码中,响应键 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 。F orms.keys%28v = vs.110%29.aspx [ ^ ]。



当输入时,调用相同的你在确定按钮上点击点击事件处理程序的事情(如果有的话,在OK的对话框的模态状态结束时)。检查用户名和密码字段的值并禁用确定和键盘操作也是很好的,除非它们都有一些数据,非空且不包含空格。



-SA
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


这篇关于如果我在输入密码后按Enter键,如何使密码框工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆