none
Drawing a multicolor line in GDI+ RRS feed

  • Question

  • Hi,  I want to draw a dashed line,  but with a red dash followed by a blue dash repeating along the line.   Is there any way to construct a Pen to do that?  I know how to draw a dashed line in a single color.

    I expect I could draw a solid red line,  then draw a blue dashed line directly on top of it so the red line would show through where the empty space is in the blue line,  but that seems a little messy.   Is there a better way?

    Thanks,

    Michael

    Tuesday, January 19, 2016 2:32 PM

Answers

  • Hi Michael,

    Your idea is good to me.

    By the way, GDI+ provides several dash styles that are listed in the DashStyle enumeration. If those standard dash styles do not suit your needs, you can create a custom dash pattern.

                float[] dashValues = { 5, 2, 15, 4 };
                Pen blackPen = new Pen(Color.Black, 5);
                blackPen.DashPattern = dashValues;
                e.Graphics.DrawLine(blackPen, new Point(5, 5), new Point(405, 5));

    Hope this helps!

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, January 20, 2016 2:56 AM