Visual Basic 2005 Cookbook: Solutions for VB 2005 Programmers (Cookbooks (OReilly))
Problem
On a form, you want to have the Enter key trigger a specific button (such as an "OK" button) and have the Escape key trigger another button (such as a "Cancel" button). Solution
Use the form's AcceptButton and CancelButton properties to assign the appropriate buttons. In the Visual Studio Form Designer, setting these form properties to the names of buttons on the form will enable the keyboard shortcuts for those buttons. Discussion
Setting a button to be a form's CancelButton object has the side effect of changing that button's DialogResult property to Cancel. Even if you set an accept button, the Enter key doesn't always trigger it. For instance, if another button on the form has the focus, that button, and not the form's accept button, is triggered when the user presses the Enter key. |
Категории