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

Da Gambas-it.org - Wikipedia.
 
Riga 17: Riga 17:
 
   
 
   
 
  End
 
  End
 +
 
   
 
   
 
  Public Sub DrawingArea1_MouseUp()
 
  Public Sub DrawingArea1_MouseUp()
Riga 37: Riga 38:
 
      
 
      
 
  End
 
  End
 +
 
   
 
   
 
  Public Sub Etichetta_MouseMove()
 
  Public Sub Etichetta_MouseMove()
Riga 47: Riga 49:
 
    
 
    
 
  End
 
  End
 +
 
   
 
   
 
  Public Sub Etichetta_MouseUp()
 
  Public Sub Etichetta_MouseUp()

Versione attuale delle 14:52, 27 giu 2024

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: