Returns or sets a value indicating whether a command button is the Cancel or Default button on a form.
Command.Cancel [ = Boolean ]
Command.Default [ = Boolean ]
Only one Command button on any one form can be the Cancel button so, when the Cancel property is set to True for one Command, it's automatically set to False for all other Command controls on the same form. Similarly with the Default property: only one Command can have the Default property set. However, it is possible that one button can be both the Cancel AND Default control.
A Command button with either of these properties set can be selected just like any other button: by clicking it or pressing ENTER when the control has focus. However, in addition, these Command controls can be activated even when they do not have the focus by pressing ESC for the Cancel button and ENTER (if no other Command has the focus) for the Default.
OpenW 1
Ocx Command cmdOk = "OK", 20, 20, 50 * 2, 14 * 2
.Default = True
Ocx Command cmdCancel = "Cancel", 20, 50, 50 * 2, 14 * 2
.Cancel = True
Do
Sleep
Until Me Is Nothing
Sub cmdOk_Click
MsgBox "OK button selected"
EndSub
Sub cmdCancel_Click
MsgBox "Cancel button selected"
Win_1.Close
EndSub
When you have a dialog box with an OK and/or Cancel button, do not give the keys accelerators. The dialog manager already has those buttons covered. The hotkey for the OK button is Enter (since it is the default pushbutton), and the hotkey for the Cancel button is ESC (since its ID is IDCANCEL).
Of course that during the lifetime of a dialog box, the default pushbutton may change, but the principle still stands: Do not give the OK button a keyboard accelerator.
Finally, don't forget that the recommended minimum size for pushbuttons is 50 dialog units by 14 dialog units.
{Created by Sjouke Hamstra; Last updated: 11/10/2017 by James Gaite}