我有下面的代码,用一个(非常)小的箭头画一条线。。。
private void Form1_Paint(object sender, PaintEventArgs e) { Pen p = new Pen(Color.Black); p.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor; e.Graphics.DrawLine(p, 10, 10, 100, 100); p.Dispose(); }
大的 箭头( 圆、正方形、三角形 等等……), 保持相同的线宽 .
有可能吗?
你应该用 CustomLineCap GraphicsPath
CustomLineCap
GraphicsPath
using(Pen p = new Pen(Color.Black)) using(GraphicsPath capPath = new GraphicsPath()) { // A triangle capPath.AddLine(-20, 0, 20, 0); capPath.AddLine(-20, 0, 0, 20); capPath.AddLine(0, 20, 20, 0); p.CustomEndCap = new System.Drawing.Drawing2D.CustomLineCap(null, capPath); e.Graphics.DrawLine(p, 0, 50, 100, 50); }
你想“设计”你的帽子与一条线从上到下,从(0,0)得到正确的坐标。
编辑 :我只想提一下,您也可以使用 AdjustableArrowCap
AdjustableArrowCap