如果我在输入密码后按Enter键,如何使密码框工作?

编程入门 行业动态 更新时间:2024-10-28 00:24:49
本文介绍了如果我在输入密码后按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 使用密码: msdn.microsoft/en-us/library/system.windows.forms.control.keydown%28v=vs.110%29.aspx [ ^ ], msdn.microsoft/en-us/library/system.windows.forms.control.keyup%28v=vs.110%29.aspx [ ^ ], msdn.microsoft/ en-us / library / system.windows.forms.keyeventargs%28v = vs.110%29.aspx [ ^ ]。 在事件处理程序代码中,响应键 System.Windows.Forms.Enter : msdn.microsoft/en-us/library/system .windows.forms.keyeventargs.keycode%28v = vs.110%29.aspx [ ^ ], msdn.microsoft/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: msdn.microsoft/en-us/library/system.windows.forms.control.keydown%28v=vs.110%29.aspx[^], msdn.microsoft/en-us/library/system.windows.forms.control.keyup%28v=vs.110%29.aspx[^], msdn.microsoft/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: msdn.microsoft/en-us/library/system.windows.forms.keyeventargs.keycode%28v=vs.110%29.aspx[^], msdn.microsoft/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键,如何使密码框工作?

本文发布于:2023-10-25 18:41:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1527772.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:我在   输入密码   密码   工作   Enter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!