tags:

views:

26

answers:

1

Result:

alt text

Question:

Can I round or do something with this line "appendix"?

Code:

    private void Form1_Paint(object sender, PaintEventArgs e)
    {
        Point[] points1 = new Point[] {
            new Point(50, 90),
            new Point(60, 20),
            new Point(70, 120)
        };

        GraphicsPath path1 = new GraphicsPath();
        path1.AddLines(points1);

        ControlPaint.DrawGrid(e.Graphics, this.ClientRectangle,
            new Size(10, 10), Color.Red);

        using (Pen p = Pens.DarkBlue.Clone() as Pen)
        {
            p.Width = 5;
            e.Graphics.DrawPath(p, path1);
            e.Graphics.DrawString("Width: " + p.Width, 
                new Font(this.Font, FontStyle.Bold), 
                Brushes.DarkBlue, new Point(35, 150));

            Matrix m = new Matrix();
            m.Translate(50, 0);
            e.Graphics.Transform = m;

            p.Width = 1;
            e.Graphics.DrawPath(p, path1);
            e.Graphics.DrawLine(Pens.Red, -40, 20, 150, 20);
            e.Graphics.DrawString("Width: " + p.Width, 
                this.Font, Brushes.DarkBlue, new Point(35, 150));
        }
    }
+4  A: 

Just change Pen.LineJoin to LineJoin.Round. You can also lower Pen.MiterLimit to clip very long corners.

Daniel Brückner
Thank you, Daniel, this is exactly I was searching for. I used `LineJoin.Bevel;`
serhio
How do you think, what method Round or Bevel is more performant?
serhio
I have no idea - profile it.
Daniel Brückner