Capture Enter Key in Editbox to close modal form

I have a form that prompts for a password using an editbox on a modal form. The OK and Cancel buttons work fine to close the form and either continue or abort. I want to capture the Enter and Esc keys in the edit box to simulate the OK click and the Cancel click. I have put code in the keypress event. It calls the click event for the buttons, but then just sits there.
Who is Participating?
rfwoolfConnect With a Mentor Commented:
Use the keyeevent to set the modal result of your form to something other than 0, e.g.
form2.ModalResult := 1;
rfwoolfConnect With a Mentor Commented:
I have a feeling that what you were doing wrong was you were calling the button's onclick event, e.g.
instead of;

OR... the other way round.

But I could be wrong... :P
SantaRosaAuthor Commented:
I had submitted the question. Both solutions work easily. Turn around time was terrific. Thankyou.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.