Differenze tra le versioni di "Evidenziare il puntatore del mouse quando si clicca sulla DrawingArea"
Da Gambas-it.org - Wikipedia.
Riga 8: | Riga 8: | ||
Private ct As Short | Private ct As Short | ||
− | + | Public Sub _new() | |
With Me | With Me | ||
Riga 19: | Riga 19: | ||
End With | End With | ||
− | + | End | |
− | + | ||
+ | Public Sub DrawingArea1_MouseUp() | ||
If Mouse.Left Then | If Mouse.Left Then | ||
Riga 37: | Riga 38: | ||
Endif | Endif | ||
− | + | End | |
+ | |||
− | + | Public Sub DrawingArea1_Draw() | |
If Not Object.IsValid(pt) Then Return | If Not Object.IsValid(pt) Then Return | ||
Riga 54: | Riga 56: | ||
End With | End With | ||
− | + | End | |
In quest'altro esempio, analogo al precedente, rimarranno visibilii i punti già disegnati: | In quest'altro esempio, analogo al precedente, rimarranno visibilii i punti già disegnati: | ||
Riga 64: | Riga 66: | ||
− | + | Public Sub _new() | |
With Me | With Me | ||
Riga 75: | Riga 77: | ||
End With | End With | ||
− | + | End | |
+ | |||
− | + | Public Sub DrawingArea1_MouseUp() | |
If Mouse.Left Then | If Mouse.Left Then | ||
Riga 93: | Riga 96: | ||
Endif | Endif | ||
− | + | End | |
+ | |||
− | + | Public Sub DrawingArea1_Draw() | |
If Not Object.IsValid(pt) Then Return | If Not Object.IsValid(pt) Then Return | ||
Riga 117: | Riga 121: | ||
End With | End With | ||
− | + | End |
Versione attuale delle 12:03, 27 giu 2024
Disegnare dei cerchi concentrici intorno al puntatore del mouse quando si clicca sulla DrawingArea
Per evidenziare il puntatore del mouse quando si clicca sulla DrawingArea, si può ad esempio disegnare dei cerchi concentrici intorno ad esso.
Mostriamo un semplice esempio pratico, nel quale i cerchi concentrici sono disegnati in sequenza dal maggiore sino al minore. Ciascun cerchio concentrico resta visibile sino a quando non è designato il successivo minore.
Private DrawingArea1 As DrawingArea Private Const ATTESA As Single = 0.1 Private pt As Point Private ct As Short 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.SoftYellow End With End Public Sub DrawingArea1_MouseUp() If Mouse.Left Then Dim c As Short pt = New Point(Mouse.X, Mouse.Y) ' Fornisce i dati per far disegnare in sequenza sulla "DrawingArea", dei cerchi concentrici: For c = 28 DownTo 1 Step 3 ct = c DrawingArea1.Refresh ' Imposta il tempo di attesa per disegnare in sequenza ciascun cerchio concentrico: Wait ATTESA Next ' Al termine dell'effetto del disegno dei cerchi concentrici, mostra le ccordinate x,y del punto ove si è cliccato sulla "DrawingArea": Me.Text = CStr(pt.X) & " " & CStr(pt.Y) Endif End Public Sub DrawingArea1_Draw() If Not Object.IsValid(pt) Then Return With Paint .Brush = .Color(Color.Red) .Arc(pt.X, pt.Y, 2 * ct, Rad(0), Rad(360), False) If ct > 1 Then .Stroke Else .Fill Endif .End End With End
In quest'altro esempio, analogo al precedente, rimarranno visibilii i punti già disegnati:
Private DrawingArea1 As DrawingArea Private Const ATTESA As Single = 0.1 Private pt As Point Private ct As Short Private punti As New Point[] 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.SoftYellow End With End Public Sub DrawingArea1_MouseUp() If Mouse.Left Then Dim c As Short pt = New Point(Mouse.X, Mouse.Y) ' Fornisce i dati per far disegnare in sequenza sulla "DrawingArea", dei cerchi concentrici: For c = 28 DownTo 1 Step 3 ct = c DrawingArea1.Refresh ' Imposta il tempo di attesa per disegnare in sequenza ciascun cerchio concentrico: Wait ATTESA Next ' Al termine dell'effetto del disegno dei cerchi concentrici, mostra le ccordinate x,y del punto ove si è cliccato sulla "DrawingArea": Me.Text = CStr(pt.X) & " " & CStr(pt.Y) Endif End Public Sub DrawingArea1_Draw() If Not Object.IsValid(pt) Then Return Dim c As Short With Paint .Brush = .Color(Color.Red) .Arc(pt.X, pt.Y, 2 * ct, Rad(0), Rad(360), False) If ct > 1 Then .Stroke Else .Fill punti.Push(pt) Endif For c = 0 To punti.Max .Arc(punti[c].X, punti[c].Y, 2, Rad(0), Rad(360), False) Next .Fill .End End With End