Differenze tra le versioni di "Creare uno pseudo-slider avente due indicatori per un ambito con un valore minimo e un valore massimo"

Da Gambas-it.org - Wikipedia.
(Creata pagina con "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 Drawing...")
 
 
Riga 3: Riga 3:
 
  Private bt1 As Button
 
  Private bt1 As Button
 
  Private bt2 As Button
 
  Private bt2 As Button
Private spx As Short
 
Private spy As Short
 
 
   
 
   
 
   
 
   
  '''Public''' Sub Form_Open()
+
  Public Sub Form_Open()
 
   
 
   
 
   With DrawingArea1 = New DrawingArea(Me) As "DrawingArea1"
 
   With DrawingArea1 = New DrawingArea(Me) As "DrawingArea1"
Riga 34: Riga 32:
 
   Me.Title = "Min = 0" & "  Max = " & CStr(bt2.X)
 
   Me.Title = "Min = 0" & "  Max = " & CStr(bt2.X)
 
   
 
   
  '''End'''
+
  End
 
   
 
   
  '''Public''' Sub DrawingArea1_Draw()
+
  Public Sub DrawingArea1_Draw()
 
   
 
   
 
   With Paint
 
   With Paint
Riga 45: Riga 43:
 
   End With
 
   End With
 
    
 
    
  '''End'''
+
  End
 
   
 
   
  '''Public''' Sub BT_MouseDown()
+
  Public Sub BT_MouseMove()
 
  spx = Mouse.X
 
  spy = Mouse.Y
 
 
'''End'''
 
 
'''Public''' Sub BT_MouseMove()
 
 
   
 
   
 
   With Last
 
   With Last
     .X = .X + Mouse.X - spx
+
     .X = .X + Mouse.X - Mouse.StartX
     .Y = .Y + Mouse.Y - spy
+
     .Y = .Y + Mouse.Y - Mouse.StartY
 
   End With
 
   End With
 
   
 
   
Riga 70: Riga 61:
 
   Me.Title = "Min = " & CStr(bt1.X) & "  Max =" & CStr(bt2.X)
 
   Me.Title = "Min = " & CStr(bt1.X) & "  Max =" & CStr(bt2.X)
 
   
 
   
  '''End'''
+
  End

Versione attuale delle 11:19, 13 giu 2023

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