UIC 上的键盘操作 - C#
i have a login form
(source: deviantart.net)
what i want is that after i have filled the password field when i press "Enter", it performs some action, some set of lines of code, in my case the same that the "Login button does". how to do it
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在密码文本框中添加用于按键的事件处理程序,在该事件处理程序中检查 Enter 键,并调用登录按钮绑定到的 (eventhandler) 方法。
Add an eventhandler for keypress on the password textbox, in that eventhandler you check for the enter key, and call the (eventhandler) method that the login button is bound to.
将表单的
AcceptButton
设置为“登录”按钮,并在其点击处理程序中编写执行登录的“代码行”。如果未填写用户名或密码,您可以禁用“登录”按钮。将两个文本框对象的
TextChanged
事件连接到执行以下操作的事件处理程序:仅处理 Enter 键按下密码字段对于用户来说可能非常不直观。假设他填写了密码框,然后返回到用户名字段以更正拼写错误,然后按 Enter 键。如果您刚刚处理了密码文本框的 KeyPress 并检查了它,它将不起作用,这会让用户感到沮丧。
Set the form's
AcceptButton
to the "Log In" button and write the "lines of code" that perform the login in its click handler.You can disable the "Log In" button if the username or password is not filled in. Wire up the
TextChanged
event of both textbox object to an event handler that does this:Handling the Enter key press only in the password field can be very nonintuitive to the user. Assume he fills the password box and moves back to the username field to correct a typo and then presses Enter. It won't work if you have just handled KeyPress for password textbox and checked for it and this will make the user frustrated.