Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I trigger the default button on a form without clicking it (winforms)?

Tags:

c#

winforms

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!

thanx in advance. srini.

like image 791
srinivas Avatar asked Jul 08 '09 12:07

srinivas


2 Answers

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.

like image 136
Simon P Stevens Avatar answered Oct 08 '22 02:10

Simon P Stevens


Simon P Stevens gave you the most adequate answer.

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.

Quick summary

Enter --> AcceptButton

Esc --> CancelButton

like image 25
elpipo Avatar answered Oct 08 '22 03:10

elpipo