OKButton (statement)


OKButton X,Y,width,height [,.Identifier]


Creates an OK button within a dialog box template.


This statement can only appear within a dialog box template (that is, between the Begin Dialog and End Dialog statements).

The OKButton statement accepts the following parameters:





X, Y

Integer coordinates specifying the position of the control (in dialog units) relative to the upper left corner of the dialog box.


width, height

Integer coordinates specifying the dimensions of the control in dialog units.



Name by which this control can be referenced by statements in a dialog function (such as DlgFocus and DlgEnable).


If the DefaultButton parameter is not specified in the Dialog statement, the OK button will be used as the default button. In this case, the OK button can be selected by pressing Enter on a nonbutton control.

A dialog box template must contain at least one OKButton, CancelButton, or PushButton statement (otherwise, the dialog box cannot be dismissed).


This example shows how to use the OK and Cancel buttons within a dialog box template and how to detect which one closed the dialog box.

Sub Main()
  Begin Dialog QuitDialogTemplate 16,32,116,64,"Quit"
    Text 4,8,108,8,"Are you sure you want to exit?"
    CheckBox 32,24,63,8,"Save Changes",.SaveChanges
    OKButton 12,40,40,14
    CancelButton 60,40,40,14
  End Dialog
  Dim QuitDialog As QuitDialogTemplate
  rc% = Dialog(QuitDialog)
  Select Case rc%
    Case -1
      MsgBox "OK was pressed!"
    Case 1
      MsgBox "Cancel was pressed!"
  End Select
End Sub

See Also

CancelButton (statement); CheckBox (statement); ComboBox (statement); Dialog (function); Dialog (statement); DropListBox (statement); GroupBox (statement); ListBox (statement); OptionButton (statement); OptionGroup (statement); Picture (statement); PushButton (statement); Text (statement); TextBox (statement); Begin Dialog (statement), PictureButton (statement).

More information