Differenze tra le versioni di "Spostare con il mouse un Controllo grafico generato in una DrawingArea"
Da Gambas-it.org - Wikipedia.
Riga 3: | Riga 3: | ||
Private lb As Label | Private lb As Label | ||
Private i As Integer | Private i As Integer | ||
− | |||
− | |||
Riga 53: | Riga 51: | ||
If Not Mouse.Left Then Return | If Not Mouse.Left Then Return | ||
− | + | <FONT Color=gray>' ''Genera e imposta una "Label", assegnadola come "figlia" alla "DrawingArea":''</font> | |
− | + | With lb = New Label(DrawingArea1) As "Etichetta" | |
− | With lb | + | .Text = " Label " & CStr(i) |
.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 | End | ||
Riga 74: | Riga 68: | ||
Last.Mouse = 18 | Last.Mouse = 18 | ||
With Last | With Last | ||
− | .X = .X + Mouse.X - | + | .X = .X + Mouse.X - Mouse.StartX |
− | .Y = .Y + Mouse.Y - | + | .Y = .Y + Mouse.Y - Mouse.StartY |
End With | End With | ||
Versione delle 09:52, 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_MouseDown() ' 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" .X = Mouse.X .Background = Color.SoftOrange .Border = Border.Raised .Text = " Label " & CStr(i) End With End Public Sub DrawingArea1_MouseMove() ' Se non si è cliccato con il tasto sinistro del mouse, si esce dalla routine: If Not Mouse.Left Then Return DrawingArea1.Mouse = 18 lb.X = Mouse.X lb.Y = Mouse.Y 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 ' 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: