提供一个vb.net的函数,自己翻译下吧Private Sub DrawArrow(ByVal S_Graphics As Graphics, ByVal pen1 As Pen, ByVal X0 As Single, ByVal Y0 As Single, ByVal X1 As Single, ByVal Y1 As Single, ByVal ArrowLen As Single) Dim Xa As Single, Ya As Single, Xb As Single, Yb As Single, D As Double D = System.Math.Sqrt((Y1 - Y0) * (Y1 - Y0) + (X1 - X0) * (X1 - X0)) If D > 0.0000000001 Then Xa = X1 + ArrowLen * MZoom * ((X0 - X1) + (Y0 - Y1) / 4) / D Ya = Y1 + ArrowLen * MZoom * ((Y0 - Y1) - (X0 - X1) / 4) / D Xb = X1 + ArrowLen * MZoom * ((X0 - X1) - (Y0 - Y1) / 4) / D Yb = Y1 + ArrowLen * MZoom * ((Y0 - Y1) + (X0 - X1) / 4) / D S_Graphics.DrawLine(pen1, Xa, Ya, X1, Y1) S_Graphics.DrawLine(pen1, Xb, Yb, X1, Y1) 'S_Graphics.DrawLine(New Pen(Color.Black, xk * Zoom), X0, Y0, X1, Y1) '如果仅画箭头,此句可删除 End If End Sub
Graphics g = your graphics; g.SmoothingMode = SmoothingMode.HighQuality; using (Pen pen = new Pen(Color.Blue, thickness))//thickness { pen.EndCap = LineCap.Custom; pen.CustomEndCap = new AdjustableArrowCap(4f, 4f, false); g.DrawLine(pen, x1, y1, x2, y2); }Have a try.
Dim Xa As Single, Ya As Single, Xb As Single, Yb As Single, D As Double
D = System.Math.Sqrt((Y1 - Y0) * (Y1 - Y0) + (X1 - X0) * (X1 - X0))
If D > 0.0000000001 Then
Xa = X1 + ArrowLen * MZoom * ((X0 - X1) + (Y0 - Y1) / 4) / D
Ya = Y1 + ArrowLen * MZoom * ((Y0 - Y1) - (X0 - X1) / 4) / D
Xb = X1 + ArrowLen * MZoom * ((X0 - X1) - (Y0 - Y1) / 4) / D
Yb = Y1 + ArrowLen * MZoom * ((Y0 - Y1) + (X0 - X1) / 4) / D
S_Graphics.DrawLine(pen1, Xa, Ya, X1, Y1)
S_Graphics.DrawLine(pen1, Xb, Yb, X1, Y1)
'S_Graphics.DrawLine(New Pen(Color.Black, xk * Zoom), X0, Y0, X1, Y1) '如果仅画箭头,此句可删除
End If
End Sub
Graphics g = your graphics;
g.SmoothingMode = SmoothingMode.HighQuality;
using (Pen pen = new Pen(Color.Blue, thickness))//thickness
{
pen.EndCap = LineCap.Custom;
pen.CustomEndCap = new AdjustableArrowCap(4f, 4f, false);
g.DrawLine(pen, x1, y1, x2, y2);
}Have a try.