Contents Previous Next Subchapters

Using Radio Buttons In A Dialog Window
See Also checkbox , popupmenu

Description
Dialog "radiobuttons" controls are used to display a list from which the user can make one choice.

addcontrol(
captiongeometry, "radiobuttons", names)
addcontrol(
captiongeometry, "radiobuttons", namescall back)
Adds a "radiobuttons" control, with the specified geometry , to the Dialog window specified by caption . The row dimension of the character matrix names specifies the number of radio buttons in this set and each row contains the text that is placed to the right of the corresponding button. The command specified by call back is executed when the currently chosen button is changed by the user. The return value is the control handle for the set of radio buttons.

The geometry specifies the size of each individual radio button, including its label. The height for the total set of radio button is the height specified in geometry times the number of rows in the matrix names.

getcontrol(
handle)
Returns the current choice for the "radiobuttons" control specified by handle, where handle is the value returned by addcontrol when the "radiobuttons" control was created. The return value is a logical column vector with the same row dimension as names in the corresponding call to addcontrol. One and only one element of the return value is true and the corresponding row of names is the current choice from the set of radio buttons.

setcontrol(
handleflag)
Changes the current choice for the "radiobuttons" control specified by handle to the value specified flag, where handle is value returned by addcontrol when the "radiobuttons" control was created and flag is a logical column vector with the same row dimension as names. One and only one element of flags is true and the corresponding row of names is the current choice from the set of radio buttons. The return value of setcontrol is true, if the control can be set as requested, and false otherwise.

Example
The following program creates a dialog window with a push button labeled "Done" and a set of radio buttons. Initially, the last choice of the radio buttons is selected. When the button is pressed, the name of the currently chosen radio button is printed in the command window and the dialog is deleted.

clear
#
Caption  = "Test Dialog"
geometry = [100, 100, 200, 150]
callback = "delwin(Caption);"
adddialog(Caption, geometry, callback);
#
geometry = [20, 20, 100, 20]
Names    = { "One", "Two", "Three"}
Handle   = addcontrol(Caption, geometry, "radiobuttons", Names);
setcontrol(Handle, {false, false, true});
#
geometry = [70, 90, 50, 20]
name     = "Done"
callback = "Done"
addcontrol(Caption, geometry, "pushbutton", name, callback);
#
function Done() begin
     global Caption, Names, Handle
     flag = getcontrol(Handle)
     print Names.row(flag)
     delwin(Caption);
end