Contents Previous Next Subchapters

Using Text Input Fields In A Dialog Window
See Also addlabel

Description
Dialog "textfield" controls are used to display text information that the user can change.

addcontrol(
captiongeometry, "textfield")
addcontrol(
captiongeometry, "textfield", text)
addcontrol(
captiongeometry, "textfield", textcall back)
Adds a "textfield" control, with the specified geometry , to the Dialog window specified by caption . The character row vector text specifies the initial text to be placed in the field. The command specified by call back is executed whenever the contents of the text field is changed by the user. The return value is the control handle for the text field.

getcontrol(
handle)
Returns the text displayed in the "textfield" control specified by handle, where handle is the value returned by addcontrol when the "textfield" control was created. The return value is a character row vector.

setcontrol(
handletext)
Changes the text displayed in the "textfield" control specified by handle to the value specified text, where handle is value returned by addcontrol when the "textfield" control was created and text is a character row vector. 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 text field. The first time the button is pressed, the contents of the text field is changed to "modify this". The second time the button is pressed, the contents of the text field is printed in the command window and the dialog is deleted.

clear
#
Caption  = "Test Dialog"
geometry = [100, 100, 200, 100]
callback = "delwin(Caption);"
adddialog(Caption, geometry, callback);
#
geometry = [20, 20, 160, 20]
text     = "initial value"
Handle   = addcontrol(Caption, geometry, "textfield", text);
#
geometry = [70, 50, 50, 20]
name     = "Done"
callback = "Done"
addcontrol(Caption, geometry, "pushbutton", name, callback);
#
count    = 0
function Done() begin
     global Handle, count, Caption
     count = count + 1
     if count == 1 then begin
          setcontrol(Handle, "modify this");
          return
     end
     print getcontrol(Handle)
     delwin(Caption);
end