Public Sub drawline(ByVal startlineX As Integer, ByVal startlineY As Integer, ByVal endlineX As Integer, ByVal endlineY As Integer)
'trangle points
Dim points(2) As Drawing.PointF
points(0).X = (startlineX + endlineX) / 2
points(0).Y = (startlineY + endlineY) / 2
points(1).X = ((startlineX + endlineX) / 2) + 20
points(1).Y = ((startlineY + endlineY) / 2) + 20
points(2).X = ((startlineX + endlineX) / 2) + 20
points(2).Y = ((startlineY + endlineY) / 2) - 20
Dim myPen As New System.Drawing.Pen(System.Drawing.Color.Red, 4)
Dim formGraphics As System.Drawing.Graphics
formGraphics = Me.CreateGraphics()
'create line on which to place trangle
formGraphics.DrawLine(myPen, startlineX, startlineY, endlineX, endlineY)
'try to work out the rotation
Dim _rotationAngle As Double
Dim opositelength As Double
Dim ajacentlength As Double
If startlineY = endlineY Then
If startlineX > endlineX Then
_rotationAngle = 180
Else
_rotationAngle = 0
End If
ElseIf startlineX = endlineX Then
If startlineY > endlineY Then
_rotationAngle = 270
Else
_rotationAngle = 90
End If
ElseIf startlineY > endlineY Then
If startlineX > endlineX Then
opositelength = startlineY - endlineY
ajacentlength = startlineX - endlineX
_rotationAngle = 180 + (1 / Math.Tan(opositelength / ajacentlength))
Else
opositelength = startlineY - endlineY
ajacentlength = endlineX - startlineX
_rotationAngle = 90 + (1 / Math.Tan(opositelength / ajacentlength))
End If
ElseIf startlineY < endlineY Then
If startlineX > endlineX Then
opositelength = endlineY - startlineY
ajacentlength = startlineX - endlineX
_rotationAngle = 180 + (1 / Math.Tan(opositelength / ajacentlength))
Else
opositelength = endlineY - startlineY
ajacentlength = endlineX - startlineX
_rotationAngle = 180 - (180 - (1 / Math.Tan(opositelength / ajacentlength)))
End If
End If
'draw trangle and rotate to relevant position
Dim max As System.Drawing.Drawing2D.Matrix
max = formGraphics.Transform
max.RotateAt(_rotationAngle, points(0))
formGraphics.Transform = max
formGraphics.FillPolygon(Brushes.Red, points)
formGraphics.ResetTransform()
End Sub