Contents Previous Next Subchapters

Using A Slider In A Dialog Window
See Also textfield

Dialog "slider" controls display an integer value that the user can change. (In fact, from the users point of view, any ordered value can be displayed.)

captiongeometry, "slider", loweruppercall back)
Adds a "slider" control, with the specified geometry , to the window specified by caption . The integer scalars lower and upper specify the lower and upper limits for the sliders value. The command specified by call back is executed whenever the user moves the slider. The return value is the control handle for the text field.

If geometry(3) > geometry(4), the slider moves in the horizontal direction. Otherwise, the slider moves in the vertical direction. If the slider moves horizontally, the value lower corresponds to the left and upper corresponds to the right side of the slider control. If the slider moves vertically, the value lower corresponds to the bottom and upper corresponds to the top of the slider control.

Returns the current position of the "slider" control specified by handle, where handle is the value returned by addcontrol when the "slider" control was created. The return value is an integer scalar.

Changes the current position of the "slider" control specified by handle to the value specified index, where handle is value returned by addcontrol when the "slider" control was created and index is an integer scalar between the corresponding values of lower and upper. The return value of setcontrol is true, if the control can be set as requested, and false otherwise.

The following program creates a dialog window with a push button labeled "Done" and a slider with a label that contains the slider's value. The slider starts in the middle position and when the slider is moved, the label is changed to reflect the new slider position. When the button is pressed, the dialog is deleted.

Caption  = "Test Dialog"
geometry = [100, 100, 200, 120]
callback = "delwin(Caption);"
adddialog(Caption, geometry, callback);
geometry = [20, 20, 160, 20]
lower    = 1
upper    = 100
initial  = 50
Slider   = addcontrol(Caption, geometry, "slider", lower, upper, "Callback")
setcontrol(Slider, initial);
geometry = [90, 40, 30, 20]
text     = clipstr(ntoa(initial))
Label    = addcontrol(Caption, geometry, "label", text);
geometry = [70, 70, 50, 20]
name     = "Done"
callback = [ "print getcontrol(Slider); delwin(Caption);"]
addcontrol(Caption, geometry, "pushbutton", name, callback);
function Callback() begin
     global Slider, Label
     value = getcontrol(Slider)
     value = clipstr(ntoa(value))
     setcontrol(Label, value);