Click here to Skip to main content
14,494,314 members
Rate this:
Please Sign up or sign in to vote.
See more:
private void Form1_Paint(object sender, PaintEventArgs e)
{
for (int m = 0; m < 101; m++)
{
Pen greenPen = new Pen(Color.Green, 3);
Point point1 = new Point(400 - m / 2, 200);
Point point2 = new Point(500, 100);
Point point3 = new Point(600 + m / 2, 200);
Point point4 = new Point(500, 300);
Point point5 = new Point(400 - m / 2, 200);

Point[] curvePoints = { point1, point2, point3, point4, point5 };

e.Graphics.DrawCurve(greenPen, curvePoints);
this.Refresh();
}
}

What I have tried:

After compile, how to get both sides similar in the figure.
Posted
Updated 25-Mar-20 9:15am

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

First, take out the call to Refresh - it invalidates your form, and that causes another repaint!

Second, if you want the two sides the same, you need to draw two - or possibly four - curves, not just one.
A Curve is a Bezier (or more accurately a Cardinal Spline but for most applications you can ignore the difference), and they smooth out midpoints, so you won't get the same at the top, bottom, and right as you do at the start and end point on the left. If you draw the top and bottom separately, you may get what you wanted - I have no idea what you are actually expecting, so I can't be sure exactly what you need.

Bézier curve - Wikipedia[^]
Cubic Hermite spline - Wikipedia[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100