rbulph Posted December 28, 2007 Posted December 28, 2007 (edited) Why does the SetValue method of GraphicsPath.PathPoints appear to have no effect? e.g.: 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: 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? Edited December 28, 2007 by rbulph Quote
MrPaul Posted January 4, 2008 Posted January 4, 2008 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: Quote Never trouble another for what you can do for yourself.
rbulph Posted January 6, 2008 Author Posted January 6, 2008 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 that's 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 didn't express myself very clearly. I don't simply wish to add a point, but I want to extend the path from its end to that point. I'm just querying whether there isn't 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. I'm surprised that there appears not to be, but if this is indeed the case, it's not a problem. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.