User Tools

Site Tools


k17:k17.12:start

17.12 Slider - Slider

The Slider component of Gambas provides a vertical or horizontal slider. The slider is vertical if its height is greater than its width; otherwise it is horizontal. With a slider you can generate numerical values (type integer) in a certain definition range [ Zmin | Zmax ].

B1

Figure 17.12.1: Three sliders with markers

The minimum value is always on the left for a horizontal slider and on the bottom for a vertical slider. With a slider, a (formal) scale with markers can be displayed, but the current values are not shown. You must take over this task with suitable displays such as a label, progress bar or self-designed LevelBar.

17.12.1 Properties Slider

Properties of the Slider component are described in the following table:

SliderData typeDefaultDescription
MinValueInteger1Sets or returns the minimum value generated in the slider.
MaxValueInteger100Sets the maximum value that is generated in the slider or returns this value.
Mark BooleanFalseDetermines whether marks are displayed or returns this value.
StepInteger1Changes the value of the generated integer (→ Slider.Value) by the value of Step as long as the slider has focus.
PageStepInteger10Changes the value of the generated integer (→ Slider.Value) by the value of PageStep.
ValueInteger-Sets the slider value or returns the generated integer.
TrackingBooleanFalseIndicates that the slider emits the change event continuously when the slider knob is moved.

Table 17.12.1.1: Slider Properties

17.12.2 Events Slider

The Slider component has only one specific event - Change. The Change event is fired every time the value of the slider changes.

  • It changes by the value of Step when you use the cusor keys (<,>) as long as the slider has focus.
  • It changes when you click on the (highlighted) slider path.
  • It changes when you click on the (marked) slider path and hold the mouse down (repeat function).
  • It changes when you drag the knob to its new position.
  • It changes by PageStep when you press the Page_Up or Page_Down button as long as the component has focus.
  • Use the Pos1 and End keys to reach the values for .MinValue and .MaxValue.

17.12.3 Project 1 Slider

The Slider project deploys three sliders with markers and appropriate displays of each of the minimum, maximum and current values.

B2

Figure 17.12.3.1: Three sliders with markers

Figure 17.12.3.1 shows the programme window for the project presented, whose source code is given in full and commented on in selected passages:

[1] ' Gambas class file
[2]
[3] Public Sub _new()
[4]   sldVertical1.MinValue = 0
[5]   sldVertical1.MaxValue = 360
[6]   sldVertical1.Mark = True
[7]   sldVertical1.PageStep = 30
[8]   sldVertical1.Step = 1
[9]   sldVertical1.Value = 270
[10]   txbVSlider1.Text = Str(sldVertical1.Value) & "°"
[11]   sldVertical2.MinValue = 30
[12]   sldVertical2.MaxValue = 100
[13]   sldVertical2.Mark = True
[14]   sldVertical2.PageStep = 10
[15]   sldVertical2.Step = 5
[16]   sldVertical2.Value = 50
[17]   txbVSlider2.Text = Str(sldVertical2.Value) & " kN"
[18]   sldHorizontal1.MinValue = 0
[19]   sldHorizontal1.MaxValue = 100
[20]   sldHorizontal1.Mark = True
[21]   sldHorizontal1.PageStep = 5
[22]   sldHorizontal1.Step = 1
[23]   sldHorizontal1.Value = 82
[24] End
[25]
[26] Public Sub Form_Open()
[27]   FMain.Center
[28]   FMain.Resizable = False
[29]   txbVSlider1.ReadOnly = True
[30]   txbVSlider2.ReadOnly = True
[31]   ProgressBar1.Label = True
[32]   ProgressBar1.Value = sldHorizontal1.Value * 0.01
[33]   DrawLevelBar()
[34] End
[35]
[36] Public Sub sldVertical1_Change()
[37]   txbVSlider1.Text = Str(sldVertical1.Value) & "°"
[38] End
[39]
[40] Public Sub sldVertical2_Change()
[41]   Dim iInvertedValue As Integer
[42]
[43]   iInvertedValue = - sldVertical2.Value + sldVertical2.MinValue + sldVertical2.MaxValue
[44]   txbVSlider2.Text = Str(iInvertedValue) & " kN"
[45]
[46]   If iInvertedValue >= 80 Then
[47]      txbVSlider2.Foreground = Color.Red
[48]   Else
[49]      txbVSlider2.Foreground = Color.Default
[50]   Endif ' iInvertedValue >= 80 ?
[51] End
[52]
[53] Public Sub sldHorizontal1_Change()
[54]   ProgressBar1.Value = sldHorizontal1.Value * 0.01
[55]   DrawLevelBar()
[56] End ' hSlider1_Change
[57]
[58] Public Function u(iArgument As Integer) As Float
[59]   Return ((DrawingArea1.H / DrawingArea1.W) * iArgument)
[60] End
[61]
[62] Public Sub DrawLine(iArgument As Integer, fOrdinate As Float)
[63]   Draw.Foreground = Color.red
[64]   Draw.Point(iArgument, fOrdinate)
[65]   Draw.Line(iArgument, 0, iArgument, fOrdinate)
[66] End
[67]
[68] Public Sub LevelBar(iValue As Integer)
[69]   Dim iCount As Integer
[70]
[71]   For iCount = 0 To iValue Step 2 ' Alternativen: 1 und 3
[72]       DrawLine(iCount, u(iCount))
[73]   Next ' iCount
[74] End ' LevelBar(iValue As Integer)
[75]
[76] Public Sub DrawLevelBar()
[77]    Draw.Begin(DrawingArea1)
[78]     Draw.Translate(0, DrawingArea1.H) ' Erst verschieben und dann skalieren!
[79]     Draw.Scale(1, -1)
[80]     Draw.Clear
[81]     LevelBar(sldHorizontal1.Value * (DrawingArea1.W / sldHorizontal1.MaxValue))
[82]   Draw.End
[83] End
[84]
[85] Public Sub btnClose_Click()
[86]   FMain.Close
[87] End

Comments:

  • In lines 4 to 22, selected properties of the three sliders are assigned meaningful initial values.
  • Displaying the values of the vertical slider 2 in a TextBox in the unit kN represents forces above 80kN in the colour red → lines 46-50 and Figure 17.12.3.1.
  • The vertical slider 2 has, on the one hand, values for the minimum and maximum values that deviate from the default values and, on the other hand, a (seemingly) inverted display. The maximum value is at the bottom and the minimum at the top! The display of the forces below also shows this behaviour. In line 43, the inverted values are calculated as a mapping of the interval [a,e] to the interval [e,a] and then displayed.

17.12.4 Project 2 Slider

Work is only really fun with the classes for Slider by Daniel Fuchs (FH Eberswalde). This slider component has a labelled scale that can be displayed above or below a horizontal slider, for example.

The horizontal slider can be used to change the solarisation of the image in the range from 0 (complete reversal) to 100 (no reversal). The left vertical slider displays positive temperatures in the programme window on a light red background, while all temperatures in the interval [-20°C | 0°C] are displayed on a light blue background. For the 2nd vertical slider, an inverted representation is used.

B3

Figure 17.12.4.1: Slider by Daniel Fuchs (1)

B4

Figure 17.12.4.2: Slider by D. Fuchs (2)

Download

The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k17/k17.12/start.txt · Last modified: 01.10.2023 by emma

Page Tools