Search code examples
c#drawinglinebeziercurve

Drawing tapered lines programatically in c#


is it possible to draw curved tapered lines with c# via code?

i am able to draw curved lines like this:

var g = panel1.CreateGraphics();
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
var p = new Pen(Color.Black);            
var sb = new SolidBrush(Color.Red);            
PointF[] points = new PointF[] {
    new PointF(1,0),
    new PointF(100,0),
    new PointF(200,100),
    new PointF(400,0),
};
g.DrawBeziers(p,points);

but this way i cannot set different widths.

that is what i want to achieve enter image description here


Solution

  • Ok, it was easy once i knew what i had to do:

    draw 2 lines and fill the space between:

    var g = panel1.CreateGraphics();
    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
    
    PointF[] points1 = new PointF[] {
        new PointF(0,0),
        new PointF(100,150),
        new PointF(500,0),
        //new PointF(400,0),
    };
    PointF[] points2 = new PointF[] {
        new PointF(0,0),
        new PointF(100,160),
        new PointF(500,0),
        //new PointF(400,0),
    };
    
    panelPath = new GraphicsPath();
    panelPath.AddCurve(points1);
    panelPath.AddCurve(points2);
    g.FillPath(Brushes.Black, panelPath);