Creare uno pseudo-slider avente due indicatori per un ambito con un valore minimo e un valore massimo
Da Gambas-it.org - Wikipedia.
Versione del 13 giu 2023 alle 11:19 di Vuott (Discussione | contributi)
Per avere uno pseudo-slider avente due indicatori per un ambito con un valore minimo e un valore massimo, si può adottare il seguente codice:
Private DrawingArea1 As DrawingArea Private bt1 As Button Private bt2 As Button Public Sub Form_Open() With DrawingArea1 = New DrawingArea(Me) As "DrawingArea1" .X = 20 .Y = 20 .W = 300 .H = 20 .Border = Border.Solid End With With bt1 = New Button(DrawingArea1) As "BT" If Not Even(DrawingArea1.W * 0.03) Then .W = (DrawingArea1.W * 0.03) + 1 .H = DrawingArea1.H .X = 0 .Y = 0 .Text = String.Chr(&2193) End With With bt2 = New Button(DrawingArea1) As "BT" .W = bt1.W .H = DrawingArea1.H .X = DrawingArea1.W - .W .Y = 0 .Text = String.Chr(&2193) End With Me.Title = "Min = 0" & " Max = " & CStr(bt2.X) End Public Sub DrawingArea1_Draw() With Paint .Brush = Paint.Color(Color.Orange) .Rectangle(bt1.X + bt1.W, 0, (DrawingArea1.W - bt1.X) - (DrawingArea1.W - bt2.X), DrawingArea1.H) .Fill .End End With End Public Sub BT_MouseMove() With Last .X = .X + Mouse.X - Mouse.StartX .Y = .Y + Mouse.Y - Mouse.StartY End With If Last.Y <> 0 Then Last.Y = 0 If bt1.X < 0 Then bt1.X = 0 If bt2.X < bt1.W Then bt2.X = bt1.W If bt1.X > bt2.X - bt1.W Then bt1.X = bt2.X - bt1.W If bt2.X > DrawingArea1.W - bt2.W Then bt2.X = DrawingArea1.W - bt2.W ' I valori assunti dai due indicatori mobili durante il loro spostamento è mostrato nel titolo della finestra del "Form": Me.Title = "Min = " & CStr(bt1.X) & " Max =" & CStr(bt2.X) End