tomu - 10 months ago 71

C# Question

If there is a line added to a Graphicspath with two ends location defined, is it possible to read this pair of points?

`Point[] myArray =`

{

new Point(30,30),

new Point(60,60),

};

GraphicsPath myPath2 = new GraphicsPath();

myPath2.AddLines(myArray2);

from myPath2, is there something similar to

`myPath2.Location`

Thanks

Answer

Yes it is possible via `GraphicsPath.PathPoints`

but you will need to understand the 2nd array of `GraphicsPath.PathTypes`

!

Only if all the points are added as a simple point array of **line** coordinates, maybe like this:

```
List<Point> points = new List<Point>();
.. // add some points!
GraphicsPath gp = new GraphicsPath();
gp.AddLines(points.ToArray());
```

will you be able to use/modify the points without much hassle.

If you add them via **rounded** shapes, like..

```
gp.AddEllipse(ClientRectangle);
```

..you will need to understand the various types! The same is true when you add them as other curves `gp.AddCurves(points.ToArray());`

If you add them as `gp.AddRectangle(ClientRectangle);`

you will get the regular points but with a byte type that says

0 - Indicates that the point is the start of a figure.

So in your case you get at the 1st of your points like this:

```
Console.WriteLine(gp.PathPoints[1].ToString());
```

Btw: There is no such thing as a `GraphicsPath.Location`

; but you may find `GraphicsPath.GetBounds()`

useful..

Note that all rounded shapes (including arcs and ellipses!) in fact consist only of bezier points:

3 - Indicates that the point is an endpoint or control point of a cubic Bézier spline

which means that the `PathPoints`

are **alternating** endpoints and control points.

Source (Stackoverflow)