Differenze tra le versioni di "Disegnare in una DrawingArea più linee rette con il mouse"
Da Gambas-it.org - Wikipedia.
(Creata pagina con "Per disegnare su una ''DrawingArea'' con il mouse due o più linee rette in modo tale che, le linee precedentemente disegnate, restino visibili sulla ''DrawingArea'' ad ogni d...") |
|||
Riga 10: | Riga 10: | ||
Dim i As Integer | Dim i As Integer | ||
− | + | ||
− | With | + | With Paint |
− | . | + | .Brush = .Color(Color.Red) |
− | . | + | .MoveTo(StartX, StartY) |
+ | .LineTo(OldX, OldY) | ||
For i = 0 To punti.Max Step 4 | For i = 0 To punti.Max Step 4 | ||
− | . | + | .MoveTo(punti[i], punti[i + 1]) |
− | Next | + | .LineTo(punti[i + 2], punti[i + 3]) |
− | .End | + | Next |
+ | .Stroke | ||
+ | .End | ||
End With | End With | ||
− | + | ||
'''End''' | '''End''' | ||
Riga 51: | Riga 54: | ||
'''End''' | '''End''' | ||
− | |||
Versione delle 20:02, 28 nov 2020
Per disegnare su una DrawingArea con il mouse due o più linee rette in modo tale che, le linee precedentemente disegnate, restino visibili sulla DrawingArea ad ogni disegno di una nuova linea, potremo adottare un codice come il seguente: [Nota 1]
Private OldX As Single Private OldY As Single Private StartX As Single Private StartY As Single Private punti As New Integer[] Public Sub DrawingArea1_Draw() Dim i As Integer With Paint .Brush = .Color(Color.Red) .MoveTo(StartX, StartY) .LineTo(OldX, OldY) For i = 0 To punti.Max Step 4 .MoveTo(punti[i], punti[i + 1]) .LineTo(punti[i + 2], punti[i + 3]) Next .Stroke .End End With End Public Sub DrawingArea1_MouseDown() StartX = Mouse.X StartY = Mouse.Y OldX = StartX OldY = StartY End Public Sub DrawingArea1_MouseMove() OldX = Mouse.X OldY = Mouse.Y DrawingArea1.Refresh() End Public Sub DrawingArea1_MouseUp() punti.Push(StartX) punti.Push(StartY) punti.Push(OldX) punti.Push(OldY) End
Note
[1] Il codice è stato realizzato dall'utente Gianluigi del forum gambas-it.org .