Disegnare in una DrawingArea un romboide: differenze tra le versioni
Vai alla navigazione
Vai alla ricerca
Nessun oggetto della modifica |
Nessun oggetto della modifica |
||
| Riga 1: | Riga 1: | ||
Di seguito mostreremo un possibile codice per disegnare un Romboide su una ''DrawingArea''. | Di seguito mostreremo un possibile codice per disegnare un Romboide su una ''DrawingArea''. | ||
Private DrawingArea1 As DrawingArea | Private DrawingArea1 As DrawingArea | ||
| Riga 23: | Riga 16: | ||
Public Sub | Public Sub DrawingArea1_Draw() | ||
Dim | Dim cx As Float = DrawingArea1.W / 2 | ||
Dim cy As Float = DrawingArea1.H / 2 | |||
<FONT Color=gray>' ''Dimensioni del Romboide:''</font> | |||
Dim width As Float = DrawingArea1.W * 0.2 | |||
Dim height As Float = DrawingArea1.H * 0.125 | |||
<FONT Color=gray>' ''Spostamento orizzontale per inclinare il romboide:''</font> | |||
Dim offset As Float = width * 0.3 | |||
Dim points As New PointF[4] | |||
<FONT Color=gray>' ''Definisce i 4 vertici del romboide senza riempimento:''</font> | |||
points[0] = New PointF(cx - width / 2 + offset, cy - height / 2) | |||
points[1] = New PointF(cx + width / 2 + offset, cy - height / 2) | |||
points[2] = New PointF(cx + width / 2 - offset, cy + height / 2) | |||
points[3] = New PointF(cx - width / 2 - offset, cy + height / 2) | |||
With Paint | With Paint | ||
. | .Brush = Paint.Color(Color.Black) | ||
. | .LineWidth = 2 | ||
. | .MoveTo(points[0].X, points[0].Y) | ||
For i As Integer = 1 To 3 | |||
.LineTo(points[i].X, points[i].Y) | |||
Next | |||
.LineTo(points[0].X, points[0].Y) | |||
.Stroke | .Stroke | ||
End With | End With | ||
End | End | ||
Versione attuale delle 22:31, 27 lug 2025
Di seguito mostreremo un possibile codice per disegnare un Romboide su una DrawingArea.
Private DrawingArea1 As DrawingArea
Public Sub Form_Open()
With Me
.Move(0, 0, Screen.AvailableWidth, Screen.AvailableHeight)
.Arrangement = Arrange.Fill
End With
With DrawingArea1 = New DrawingArea(Me) As "DrawingArea1"
.Background = Color.Lighter(Color.Yellow)
End With
End
Public Sub DrawingArea1_Draw()
Dim cx As Float = DrawingArea1.W / 2
Dim cy As Float = DrawingArea1.H / 2
' Dimensioni del Romboide:
Dim width As Float = DrawingArea1.W * 0.2
Dim height As Float = DrawingArea1.H * 0.125
' Spostamento orizzontale per inclinare il romboide:
Dim offset As Float = width * 0.3
Dim points As New PointF[4]
' Definisce i 4 vertici del romboide senza riempimento:
points[0] = New PointF(cx - width / 2 + offset, cy - height / 2)
points[1] = New PointF(cx + width / 2 + offset, cy - height / 2)
points[2] = New PointF(cx + width / 2 - offset, cy + height / 2)
points[3] = New PointF(cx - width / 2 - offset, cy + height / 2)
With Paint
.Brush = Paint.Color(Color.Black)
.LineWidth = 2
.MoveTo(points[0].X, points[0].Y)
For i As Integer = 1 To 3
.LineTo(points[i].X, points[i].Y)
Next
.LineTo(points[0].X, points[0].Y)
.Stroke
End With
End