Differenze tra le versioni di "Spostare con il mouse un Controllo grafico generato in una DrawingArea"

Da Gambas-it.org - Wikipedia.
 
(Una versione intermedia di uno stesso utente non è mostrata)
Riga 3: Riga 3:
 
  Private lb As Label
 
  Private lb As Label
 
  Private i As Integer
 
  Private i As Integer
Private spx As Short
 
Private spy As Short
 
 
   
 
   
 
   
 
   
Riga 20: Riga 18:
 
  End
 
  End
 
   
 
   
  Public Sub DrawingArea1_MouseDown()
+
  Public Sub DrawingArea1_MouseUp()
 
   
 
   
 
  <FONT Color=gray>' ''Se non si è cliccato con il tasto sinistro del mouse, si esce dalla routine:''</font>
 
  <FONT Color=gray>' ''Se non si è cliccato con il tasto sinistro del mouse, si esce dalla routine:''</font>
Riga 26: Riga 24:
 
   
 
   
 
   Inc i
 
   Inc i
 
+
 
  <FONT Color=gray>' ''Genera e imposta una "Label", assegnadola come "figlia" alla "DrawingArea":''</font>
 
  <FONT Color=gray>' ''Genera e imposta una "Label", assegnadola come "figlia" alla "DrawingArea":''</font>
 
   With lb = New Label(DrawingArea1) As "Etichetta"
 
   With lb = New Label(DrawingArea1) As "Etichetta"
    .X = Mouse.X
 
    .Background = Color.SoftOrange
 
    .Border = Border.Raised
 
 
     .Text = " Label " & CStr(i)
 
     .Text = " Label " & CStr(i)
  End With
 
   
 
End
 
 
Public Sub DrawingArea1_MouseMove() 
 
 
 
<FONT Color=gray>' ''Se non si è cliccato con il tasto sinistro del mouse, si esce dalla routine:''</font>
 
  If Not Mouse.Left Then Return
 
 
  DrawingArea1.Mouse = 18
 
  lb.X = Mouse.X
 
  lb.Y = Mouse.Y
 
 
 
End
 
 
Public Sub DrawingArea1_MouseUp()
 
 
<FONT Color=gray>' ''Se non si è cliccato con il tasto sinistro del mouse, si esce dalla routine:''</font>
 
  If Not Mouse.Left Then Return
 
 
  DrawingArea1.Mouse = Mouse.Default
 
 
 
  With lb
 
 
     .W = .Font.TextWidth(.Text) + 5
 
     .W = .Font.TextWidth(.Text) + 5
 
     .H = .Font.TextHeight(.Text)
 
     .H = .Font.TextHeight(.Text)
 +
    .X = Mouse.X
 
     .Y = Mouse.Y - .H
 
     .Y = Mouse.Y - .H
 +
    .Background = Color.SoftOrange
 +
    .Border = Border.Raised
 
   End With
 
   End With
 
      
 
      
End
 
 
Public Sub Etichetta_MouseDown()
 
 
 
  spx = Mouse.X
 
  spy = Mouse.Y
 
 
 
 
  End
 
  End
 
   
 
   
Riga 74: Riga 42:
 
   Last.Mouse = 18
 
   Last.Mouse = 18
 
   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
 
    
 
    

Versione attuale delle 09:54, 13 giu 2023

Il seguente codice ci consente di creare e di spostare all'interno di una DrawingArea un proprio Oggetto grafico Figlio. [nota 1]

Private DrawingArea1 As DrawingArea
Private lb As Label
Private i As Integer


Public Sub _new()

 With Me
   .W = Screen.AvailableWidth
   .H = Screen.AvailableHeight
   .Arrangement = Arrange.Fill
 End With
 With DrawingArea1 = New DrawingArea(Me) As "DrawingArea1"
   .Background = Color.White
 End With

End

Public Sub DrawingArea1_MouseUp()

' Se non si è cliccato con il tasto sinistro del mouse, si esce dalla routine:
 If Not Mouse.Left Then Return

 Inc i

' Genera e imposta una "Label", assegnadola come "figlia" alla "DrawingArea":
 With lb = New Label(DrawingArea1) As "Etichetta"
   .Text = " Label " & CStr(i)
   .W = .Font.TextWidth(.Text) + 5
   .H = .Font.TextHeight(.Text)
   .X = Mouse.X
   .Y = Mouse.Y - .H
   .Background = Color.SoftOrange
   .Border = Border.Raised
 End With
   
End

Public Sub Etichetta_MouseMove()
 
 Last.Mouse = 18
 With Last
   .X = .X + Mouse.X - Mouse.StartX
   .Y = .Y + Mouse.Y - Mouse.StartY
 End With
 
End

Public Sub Etichetta_MouseUp()
 
 Last.Mouse = Mouse.Default
 
End


Note

[1] Vedere anche le seguenti pagine: