I have two text boxes. one for login id and another is for password. and there is one button (submit). I need an event that takes the values of login id and password. I.e, without clicking the mouse I need to invoke this event(just by hitting 'enter' on keyboard). can anybody help me!
我有两个文本框。一个用于登录ID,另一个用于密码。并且有一个按钮(提交)。我需要一个采用登录ID和密码值的事件。即,没有单击鼠标我需要调用此事件(只需在键盘上点击'enter')。有谁能够帮我!
thanx in advance. srini.
提前。作者Srini。
5 个解决方案
#1
Simon P Stevens gave you the most adequate answer.
西蒙P史蒂文斯给了你最充分的答案。
I would just add that you also have the possibility to set a form's CancelButton on which a click event would be triggered when you press the escape ESC key.
我只想补充一点,你也可以设置一个表单的CancelButton,按下ESC键时会触发一个click事件。
Quick summary
Enter --> AcceptButton
输入 - > AcceptButton
Esc --> CancelButton
Esc - > CancelButton
#2
Set the button to be the accept button on the form. You can do this by setting the forms "AcceptButton" property to be the button you want to trigger. This will make an enter key press trigger the button.
将按钮设置为表单上的接受按钮。您可以通过将表单“AcceptButton”属性设置为要触发的按钮来完成此操作。这将使按下回车键触发按钮。
#3
use
buttonName.PerformClick();
#4
If you don't want the button to be the default you can hook both TextBoxes KeyPress events to same handler then check if Enter was pressed using KeyEventArgs.KeyCode.
如果您不希望该按钮成为默认按钮,则可以将两个TextBoxes KeyPress事件挂钩到相同的处理程序,然后使用KeyEventArgs.KeyCode检查是否按下了Enter。
#5
If you need to be able to navigate the form without the mouse, you'll want to make sure your tab stops are set correctly. I would set Login Id as the first, password as the second, and your submit button as the third. Then the user can navigate easily among them. IIRC, the default behavior of buttons is to fire off the On_Click event if the Enter key is pressed while the button has focus.
如果您需要能够在没有鼠标的情况下导航表单,则需要确保正确设置制表位。我将Login Id设置为第一个,将密码设置为第二个,将提交按钮设置为第三个。然后,用户可以在它们之间轻松导航。 IIRC,按钮的默认行为是在按钮具有焦点时按下Enter键时触发On_Click事件。
#1
Simon P Stevens gave you the most adequate answer.
西蒙P史蒂文斯给了你最充分的答案。
I would just add that you also have the possibility to set a form's CancelButton on which a click event would be triggered when you press the escape ESC key.
我只想补充一点,你也可以设置一个表单的CancelButton,按下ESC键时会触发一个click事件。
Quick summary
Enter --> AcceptButton
输入 - > AcceptButton
Esc --> CancelButton
Esc - > CancelButton
#2
Set the button to be the accept button on the form. You can do this by setting the forms "AcceptButton" property to be the button you want to trigger. This will make an enter key press trigger the button.
将按钮设置为表单上的接受按钮。您可以通过将表单“AcceptButton”属性设置为要触发的按钮来完成此操作。这将使按下回车键触发按钮。
#3
use
buttonName.PerformClick();
#4
If you don't want the button to be the default you can hook both TextBoxes KeyPress events to same handler then check if Enter was pressed using KeyEventArgs.KeyCode.
如果您不希望该按钮成为默认按钮,则可以将两个TextBoxes KeyPress事件挂钩到相同的处理程序,然后使用KeyEventArgs.KeyCode检查是否按下了Enter。
#5
If you need to be able to navigate the form without the mouse, you'll want to make sure your tab stops are set correctly. I would set Login Id as the first, password as the second, and your submit button as the third. Then the user can navigate easily among them. IIRC, the default behavior of buttons is to fire off the On_Click event if the Enter key is pressed while the button has focus.
如果您需要能够在没有鼠标的情况下导航表单,则需要确保正确设置制表位。我将Login Id设置为第一个,将密码设置为第二个,将提交按钮设置为第三个。然后,用户可以在它们之间轻松导航。 IIRC,按钮的默认行为是在按钮具有焦点时按下Enter键时触发On_Click事件。