There’s are a couple of form properties that kind of sneaked in DotNet development a while back. They are:
AcceptButton
CancelButton


In a form, if you want the default action to be to accept the programming of a particular button when the Enter key is pressed, you assign that button to the AcceptButton property of the form.

Let’s say you also have a ‘Cancel’ button on the form. Any time that button is pressed, you want no programming to take place and you want the form to close. There’s no programming necessary for this either – just assign that button to the ‘CancelButton’ property of the form.