The Slider class represents a slider control.
// define the slider sample form
class MyForm extends Form {
textbox = null;
constructor(caption, x_pos, y_pos, width, height) {
// the constructor gets called when a new object is created;
// the super() function calls the constructor on the base
// class, which in this case is Form since MyForm extends Form
super(caption, x_pos, y_pos, width, height);
// create a new slider, with a range from 0 to 200
// units and an initial value of 100
const slider = new Slider();
slider.setRange(0, 200);
slider.setValue(100);
// create a new line and textbox
const line = new Line(Line.Horizontal);
this.textbox = new TextBox();
this.textbox.setMultiline(true);
// connect the slider events to the slider handler; these
// handlers will be called when the corresponding slider event
// is fired; here, we use one handler, onSliderChanged, for
// simplicity, but we could also add different handlers for
// different events
slider.scroll.connect(this, this.onSliderChanged);
slider.scrollTop.connect(this, this.onSliderChanged);
slider.scrollBottom.connect(this, this.onSliderChanged);
slider.scrollUp.connect(this, this.onSliderChanged);
slider.scrollDown.connect(this, this.onSliderChanged);
slider.scrollPageUp.connect(this, this.onSliderChanged);
slider.scrollPageDown.connect(this, this.onSliderChanged);
slider.track.connect(this, this.onSliderChanged);
slider.trackRelease.connect(this, this.onSliderChanged);
// connect the form resize event
this.sizeChanged.connect(this, this.onFormSizeChanged);
// add the slider, line, and the textbox to the form
const layout_main = new BoxLayout(Layout.Vertical);
layout_main.addSpacer();
layout_main.add(slider, 0, Layout.Expand | Layout.Left | Layout.Right, 5);
layout_main.addSpacer(10);
layout_main.add(line, 0, Layout.Expand | Layout.Left | Layout.Right, 5);
layout_main.addSpacer(10);
layout_main.add(this.textbox, 1, Layout.Expand | Layout.Left | Layout.Right, 5);
layout_main.addSpacer();
// use layout_main for the main form layout
this.setLayout(layout_main);
}
onSliderChanged(sender, event_args) {
// when the slider is changed, append text to the textbox
// with the new slider value
this.textbox.appendText(`Slider changed: ${event_args.value}\n`);
}
onFormSizeChanged(sender, event_args) {
// when the form is resized, append text to the textbox
// with the new form size
const size = this.getSize();
this.textbox.appendText(`Form resized: (${size.width},${size.height})\n`);
this.layout();
}
}
// create a new slider sample form
const f = new MyForm("Slider Example", 0, 0, 400, 300);
f.center();
f.show();
Application.run(); Returns the number of steps the slider moves when the slider bar is moved.
Returns the number of steps the slider moves when the slider bar is moved.
Returns the maximum value the slider can have.
Returns the maximum value the slider can have.
Returns the minimum value the slider can have.
Returns the minimum value the slider can have.
Returns the number of steps the slider moves on page up or page down.
Returns the number of steps the slider moves on page up or page down.
Returns the position of the slider.
Returns the position of the slider.
Sets the number of steps the slider moves when the slider bar is moved.
Sets the number of steps the slider moves on page up or page down.
Sets the minimum and maximum value the slider can have.
Sets the position of the slider.