Spostare con il mouse un Controllo grafico generato in una DrawingArea

Da Gambas-it.org - Wikipedia.

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: