Take the 2-minute tour ×

I have the following code, that draws a line with a (very) small arrow...

    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);

I want to draw a big arrow (circle, square, triangle etc...), keeping the same line width.

Is it possible?

share|improve this question

1 Answer 1

up vote 10 down vote accepted

You'd want to use a CustomLineCap with a GraphicsPath. Here's an example:

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);

You want to "design" your cap with a line going top-to-bottom and from (0, 0) to get the correct coordinates.

EDIT: I just wanted to mention that you can also use AdjustableArrowCap to draw an arrow of a specific size and fill it but because you mentioned the requirement for other shapes, I've used a CustomLineCap.

share|improve this answer
yeah.. I know about customcap... the inconvenient is that it will not change with the line width... ideally for me if the cap was a property like "CapScale" or "CapSize"... but it does not exist... It also a pity that does not exist a AdjustableCircleCap or AdjustableSquareCap... –  serhio Aug 3 '10 at 8:24
@serhio - What do you mean it won't change with the line width? If you change the pen width, it will draw a thicker line. Could you explain more what you mean? You could also roll your own AdjustableCircleCap, it's not hard when you know how to use the GraphicsPath properly. If you're not sure, I can write one up for you. –  TheCloudlessSky Aug 3 '10 at 11:59
+1 for AdjustableArrowCap –  Xichen Li Mar 25 '11 at 16:53

Your Answer


