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.
cmdButton.Cancel = lIsItCancel
lIsItCancel = cmdButton.Cancel
cmdButton.Default = lIsItDefault
lIsItDefault = cmdButton.DefaultThere are two strange things associated with these two properties. One is really a Windows thing. That's the relationship between default buttons and the Enter key. Some controls, like edit boxes, accept the Enter key. Unless focus is on one of those controls, pressing Enter chooses the default button. You can specify the default button for any form. But Enter selects the default only when focus isn't on a different command button. As soon as any other button gets focus, pressing Enter chooses that button. When focus moves to a control other than a command button, the button you specified again is the recipient of any Enter.
The reason for this weird behavior is that the Enter key is seriously overloaded. Enter is one of the ways to press a button when it has focus. Enter is also the keystroke for choosing the default button. The only way to merge these two behaviors is for a button with focus to be the default button. (FoxPro/DOS solves the problem by requiring Ctrl+Enter to choose the default button.)
And finally, to answer the question you haven't asked yet, yes, a single button can be both the cancel and the default button at the same time.
* Make the OK button be the default and the Cancel
* button be the cancel button
ThisForm.cmdOK.Default=.T.
ThisForm.cmdCancel.Cancel=.T.
