Recipe 4.9. Indicating the Accept and Cancel Buttons on a Form


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).


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.


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.

Visual Basic 2005 Cookbook(c) Solutions for VB 2005 Programmers
Visual Basic 2005 Cookbook: Solutions for VB 2005 Programmers (Cookbooks (OReilly))
ISBN: 0596101775
EAN: 2147483647
Year: 2006
Pages: 400

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: