Disegnare in una DrawingArea un romboide
Vai alla navigazione
Vai alla ricerca
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