AllTheTimeWorld.com

csharp drawingBezier Curves

Bezier Curves

Bezier Curves

Bezier Curves

We will create 4 points, then use a pen to draw a Bezier curve at the point clicked
.Curve like letter J
It may help to think of a Bezier curve as stretching a rubber band.
For more information see https://www.codeproject.com/Articles/25237/Bezier-Curves-Made-Simple

Add this code to the MouseClick event:

private void Form1_MouseClick(object sender, MouseEventArgs e)
{
   // Get the graphics of the form.
   Graphics g = this.CreateGraphics();
   // Create a pen.
   Pen myPen = new Pen(Color.Red,3);
   // Create 4 points
   Point pt1 = new Point(e.X, e.Y);
   Point pt2 = new Point(e.X+40, e.Y+40);
   Point pt3 = new Point(e.X+70, e.Y);
   Point pt4 = new Point(e.X-35, e.Y -35);
   // Draw the Bezier Curve using the 4 points.
   g.DrawBezier(myPen, pt1, pt2, pt3,pt4);
}
To Do: Experiment! Try drawing other Bezier Curves.