Cicode Programming Reference > Cicode Function Categories > Form Functions Introduction > FormButton

FormButton

Adds a button to the current form. You can add buttons that run callback functions (specified in Fn) to perform any actions you need, as well as the standard buttons - an [OK] button to save the operator's entries and close the form, and a [Cancel] button to close the form but discard the changes.

You should call this function only after the FormNew() function and before the FormRead() function. The button is added to the form at the specified column and row position. The width of the button is automatically sized to suit the text.

Syntax

FormButton(Col, Row, sText, Fn, Mode)

Col:

The number of the column in which the button will be placed. Enter a number from 0 (column 1) to the form width - 1. For example, to place the button in column 8, enter 7.

Row:

The number of the row in which the button will be placed. Enter a number from 0 (row 1) to the form height - 1. For example, to place the button in row 6, enter 5.

sText:

The text to display on the button.

Fn:

The callback function to call when the button is selected. Set to 0 to call no function. Please be aware that the Fn parameter needs to be of type INT and the callback function cannot contain a blocking function.

Mode:

Button mode:

0 - Normal button. When this button is selected the callback function is called.

1 - OK button. When this button is selected, the form is closed, and all operator-entered data is copied to buffers (specified by the other form functions). FormRead() returns 0 (zero) to indicate a successful read. The callback function specified in Fn is called. Be aware that this mode destroys the form.

2 - Cancel button. When this button is selected, the form is closed and operator-entered data is discarded. FormRead() returns with an error 299. The callback function specified in Fn is called. Be aware that this mode destroys the form.

Return Value

The field handle if the button is successfully added, otherwise -1 is returned.

Related Functions

FormNew, FormRead

Example

! Create a form, add buttons and then display the form on the 
current page
FUNCTION FnMenu()
FormNew("MENU",20,6,1);
FormButton(0 ,4 ," FIND ", FindMenu, 0);
FormButton(10,4 ," TAG ", ShowTag, 0);
FormButton(0 ,5 ," CANCEL ", KillForm, 0);
FormButton(10,5 ," GOTO ", GotoPg, 0);
FormRead(0);
END

See Also

Form Functions