Differenze tra le versioni di "Creare e distruggere un Controllo grafico in una DrawingArea"
Da Gambas-it.org - Wikipedia.
(Creata pagina con "Essendo la ''DrawingArea'' un ''Container'' (''Contenitore'' di Oggetti grafici), risulta semplice creare al suo interno un ''Controllo'' grafico. <BR>Per ottenere ciò, il ''...") |
|||
Riga 20: | Riga 20: | ||
End | End | ||
+ | |||
Public Sub DrawingArea1_MouseDown() | Public Sub DrawingArea1_MouseDown() | ||
Riga 31: | Riga 32: | ||
With lb = New Label(DrawingArea1) As "Etichetta" | With lb = New Label(DrawingArea1) As "Etichetta" | ||
.X = Mouse.X | .X = Mouse.X | ||
− | |||
− | |||
.Text = " Label " & CStr(i) | .Text = " Label " & CStr(i) | ||
− | + | .W = .Font.TextWidth(.Text) * 2 | |
− | + | .H = .Font.TextHeight(.Text) * 2 | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | .W = .Font.TextWidth(.Text) | ||
− | .H = .Font.TextHeight(.Text) | ||
.Y = Mouse.Y - .H | .Y = Mouse.Y - .H | ||
+ | .Alignment = Align.Center | ||
+ | .Border = Border.Raised | ||
+ | .Background = Color.SoftOrange | ||
End With | End With | ||
End | End | ||
+ | |||
Public Sub Etichetta_MouseDown() | Public Sub Etichetta_MouseDown() | ||
Riga 59: | Riga 50: | ||
End | End | ||
+ | |||
Public Sub Etichetta_MouseUp() | Public Sub Etichetta_MouseUp() |
Versione attuale delle 16:23, 11 lug 2024
Essendo la DrawingArea un Container (Contenitore di Oggetti grafici), risulta semplice creare al suo interno un Controllo grafico.
Per ottenere ciò, il Controllo grafico dovrà essere creato come Oggetto "Figlio" della DrawingArea. [nota 1]
Mostriamo un semplice codice per creare e per distruggere con il mouse una o più Label.
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 .Text = " Label " & CStr(i) .W = .Font.TextWidth(.Text) * 2 .H = .Font.TextHeight(.Text) * 2 .Y = Mouse.Y - .H .Alignment = Align.Center .Border = Border.Raised .Background = Color.SoftOrange End With End Public Sub Etichetta_MouseDown() ' Se si clicca con il tasto destro del mouse, la "Label" puntata viene distrutta If Mouse.Right Then Last.Delete End Public Sub Etichetta_MouseUp() Last.Mouse = Mouse.Default End
Note
[1] Si veda anche questa pagina: Spostare con il mouse un Controllo grafico generato in una DrawingArea.