Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

How to draw a curve in windows application using C#?

2 Answers

Relevance
  • ?
    Lv 6
    1 decade ago
    Favorite Answer

    You can use GDI+ to draw curves in .NET framework. GDI+ supports several types of curves: ellipses, arcs, cardinal splines, and Bézier splines.

    ------Bell shaped cardinal spline------

    Point[] points = {

    new Point(0, 100),

    new Point(50, 80),

    new Point(100, 20),

    new Point(150, 80),

    new Point(200, 100)};

    Pen pen = new Pen(Color.FromArgb(255, 0, 0, 255));

    e.Graphics.DrawCurve(pen, points);

    -----Closed Cardinal Spline-----

    Point[] points = {

    new Point(60, 60),

    new Point(150, 80),

    new Point(200, 40),

    new Point(180, 120),

    new Point(120, 100),

    new Point(80, 160)};

    Pen pen = new Pen(Color.FromArgb(255, 0, 0, 255));

    e.Graphics.DrawClosedCurve(pen, points);

    ------Single Bézier Spline -----

    Point p1 = new Point(10, 100); // Start point

    Point c1 = new Point(100, 10); // First control point

    Point c2 = new Point(150, 150); // Second control point

    Point p2 = new Point(200, 100); // Endpoint

    Pen pen = new Pen(Color.FromArgb(255, 0, 0, 255));

    e.Graphics.DrawBezier(pen, p1, c1, c2, p2);

    -------Sequence of Bézier Splines -------

    Point[] p = {

    new Point(10, 100), // start point of first spline

    new Point(75, 10), // first control point of first spline

    new Point(80, 50), // second control point of first spline

    new Point(100, 150), // endpoint of first spline and

    // start point of second spline

    new Point(125, 80), // first control point of second spline

    new Point(175, 200), // second control point of second spline

    new Point(200, 80)}; // endpoint of second spline

    Pen pen = new Pen(Color.Blue);

    e.Graphics.DrawBeziers(pen, p);

    Source(s): MSDN help
  • 1 decade ago

    Here is a quick example, play around with the code..

    private void button3_Click(object sender, System.EventArgs e)

    {

    using (Graphics grf = CreateGraphics())

    {

    grf.Clear(Color.White);

    // create points for the cardinal spline curve

    Point[] pts = new Point[]

    {

    new Point(10, 210),

    new Point(150, 300),

    new Point(300, 270),

    new Point(220, 220)

    };

    // Draw the same curve with different tension values

    grf.DrawCurve(Pens.Black, pts, 1.0f);

    grf.DrawCurve(Pens.Red, pts, 0.0f);

    grf.DrawCurve(Pens.Blue, pts, 2.0f);

    }

    }

Still have questions? Get your answers by asking now.