PathPoints.SetValue appears to have no effect.

rbulph

Well-known member
Joined
Feb 17, 2003
Messages
343
Why does the SetValue method of GraphicsPath.PathPoints appear to have no effect? e.g.:

Code:
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim h As New Drawing.Drawing2D.GraphicsPath
        h.AddLine(New PointF(0, 0), New PointF(10, 10))
        Debug.Print("Before" & vbTab & h.PathPoints(1).ToString)
        h.PathPoints.SetValue(New PointF(20, 20), 1)
        Debug.Print("After" & vbTab & h.PathPoints(1).ToString)   remains 10,10
    End Sub
End Class

And, in a similar vein, can I not just add a point to the end of a GraphicsPath without having to resort to a procedure like this:

Code:
 Protected Shared Sub ExtendPath(ByRef P As Drawing2D.GraphicsPath, ByVal PNew As PointF)
        I just want to add a point at the end of the path, but it seems I always have to add a line.
        If P.PathPoints.Length > 0 Then
            P.AddLine(P.PathPoints(P.PathPoints.Length - 1), PNew)
        End If
    End Sub
?
 
Last edited by a moderator:
PathPoints is a clone of the underlying data.

Why does the SetValue method of GraphicsPath.PathPoints appear to have no effect?

A quick glance at the MSIL for the PathPoints property shows that each type it is accessed, it returns a newly created array which is merely a clone of the underlying data, so any changes made to this array will not be reflected in the GraphicsPath.

And, in a similar vein, can I not just add a point to the end of a GraphicsPath without having to resort to a procedure like this

A point on its own is pretty useless, as it does not represent anything meaningful - it cannot be scaled, for example. If you want the point to be part of a seperate area of the path i.e. not connected to the previous points, then you will need to close the current figure and start a new figure with StartFigure. Then you can start adding lines, curves etc. that make up the new figure. If you want the effect of a single pixel, I suggest adding a very small ellipse to the path.

Good luck :cool:
 
Re my first question I suppose that the path is stored as a series of arcs and lines etc., not as points so the points are just something thats calculated for my use to get some understanding of the path. The PathPoints property seems to be more like a function than a readonly Property.

For the second question, perhaps I didnt express myself very clearly. I dont simply wish to add a point, but I want to extend the path from its end to that point. Im just querying whether there isnt an inbuilt method to allow me to do this which would save me getting hold of the value of the last PathPoint each time before I do it. Im surprised that there appears not to be, but if this is indeed the case, its not a problem.
 
Back
Top