Cancel, Default
These two button properties let you make things easier for keyboard users by designating cancel (or "escape") and default buttons in a form. When a button is designated as the cancel button, pressing Escape is the same as clicking that button. Pressing Enter is like clicking the default button (unless focus is on another button). These properties correspond to the "\?" and "\!" designators for buttons in FoxPro 2.x.
Usage |
cmdButton.Cancel = lIsItCancel lIsItCancel = cmdButton.Cancel cmdButton.Default = lIsItDefault lIsItDefault = cmdButton.Default |
The second problem feels like a bug. A form set can have only one cancel button and one default button at a time. But Visual FoxPro isn't consistent about what to do if you mess up and specify more than one. When you change the Default property of any button in a form set to .T., the Default property for every other command button in the form set is set to .F. on the spot. When you set Cancel to .T., any other buttons' Cancel properties don't change. When you run the form, the first button created with Cancel=.T. wins, if it's enabled. |
When the user clicks a cancel button, CHR(27), which is ESC, gets put in the keyboard buffer. This makes it possible to test for LASTKEY()=27 in Valid events to see if the user is trying to escape. In that case, you probably want to skip validation of the current field. |
Example |
* Make the OK button be the default and the Cancel * button be the cancel button ThisForm.cmdOK.Default=.T. ThisForm.cmdCancel.Cancel=.T. |
See Also |