Disegnare in una DrawingArea un rombo: differenze tra le versioni
Vai alla navigazione
Vai alla ricerca
(Creata pagina con "Di seguito mostreremo un possibile codice per disegnare un Rombo in una ''DrawingArea''. I 4 vertici del Rombo sono stati correttamente individuati su una circonferenza ideal...") |
Nessun oggetto della modifica |
||
| (5 versioni intermedie di uno stesso utente non sono mostrate) | |||
| Riga 1: | Riga 1: | ||
Di seguito mostreremo un possibile codice per disegnare un Rombo in una ''DrawingArea''. | Di seguito mostreremo un possibile codice per disegnare un Rombo in una ''DrawingArea''. | ||
Private DrawingArea1 As DrawingArea | Private DrawingArea1 As DrawingArea | ||
| Riga 13: | Riga 6: | ||
With Me | With Me | ||
. | .Move(0, 0, Screen.AvailableWidth, Screen.AvailableHeight) | ||
.Arrangement = Arrange.Fill | .Arrangement = Arrange.Fill | ||
End With | End With | ||
| Riga 23: | Riga 15: | ||
End | End | ||
Public Sub DrawingArea1_Draw() | |||
Dim | Dim cx As Float = DrawingArea1.W / 2 <FONT Color=gray>' ''Centro X''</font> | ||
Dim cy As Float = DrawingArea1.H / 2 <FONT Color=gray>' ''Centro Y''</font> | |||
Dim width As Float = DrawingArea1.W * 0.4 <FONT Color=gray>' ''Larghezza del rombo''</font> | |||
Dim height As Float = DrawingArea1.H * 0.3 <FONT Color=gray>' ''Altezza del rombo''</font> | |||
Dim puntoRaggio As Float = 5 <FONT Color=gray>' ''Raggio del punto centrale''</font> | |||
Dim points As New PointF[4] | |||
points[0] = New PointF(cx, cy - height / 2) <FONT Color=gray>' ''Vertice superiore''</font> | |||
points[1] = New PointF(cx + width / 2, cy) <FONT Color=gray>' ''Vertice destro''</font> | |||
points[2] = New PointF(cx, cy + height / 2) <FONT Color=gray>' ''Vertice inferiore''</font> | |||
points[3] = New PointF(cx - width / 2, cy) <FONT Color=gray>' ''Vertice sinistro''</font> | |||
With Paint | With Paint | ||
. | .Brush = Paint.Color(Color.Black) | ||
.LineWidth = 2 | |||
<FONT Color=gray>' ''Disegna il rombo:''</font> | |||
.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 | |||
<FONT Color=gray>' ''Disegna il punto nero al centro:''</font> | |||
.Brush = Paint.Color(Color.Black) | |||
.Ellipse(cx - puntoRaggio, cy - puntoRaggio, puntoRaggio * 2, puntoRaggio * 2) | |||
.Fill | .Fill | ||
End With | End With | ||
End | End | ||
Versione attuale delle 22:27, 27 lug 2025
Di seguito mostreremo un possibile codice per disegnare un Rombo in 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 ' Centro X
Dim cy As Float = DrawingArea1.H / 2 ' Centro Y
Dim width As Float = DrawingArea1.W * 0.4 ' Larghezza del rombo
Dim height As Float = DrawingArea1.H * 0.3 ' Altezza del rombo
Dim puntoRaggio As Float = 5 ' Raggio del punto centrale
Dim points As New PointF[4]
points[0] = New PointF(cx, cy - height / 2) ' Vertice superiore
points[1] = New PointF(cx + width / 2, cy) ' Vertice destro
points[2] = New PointF(cx, cy + height / 2) ' Vertice inferiore
points[3] = New PointF(cx - width / 2, cy) ' Vertice sinistro
With Paint
.Brush = Paint.Color(Color.Black)
.LineWidth = 2
' Disegna il rombo:
.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
' Disegna il punto nero al centro:
.Brush = Paint.Color(Color.Black)
.Ellipse(cx - puntoRaggio, cy - puntoRaggio, puntoRaggio * 2, puntoRaggio * 2)
.Fill
End With
End