PDA

View Full Version : Looping Vertices



bluefireball
03-14-2007, 05:48 PM
Any body has a sample C# code to loop through the vertices of freeform shape? I'm not C# guru and I tried many ways and I always failed.:(

Winwaed
03-15-2007, 05:11 PM
I'd recommend Chandu Thota's "Programming MapPoint in .NET". I haven't tried it (yet), but pg.108 has the following code:

object[] vertices = shape.Vertices as object[];
foreach(object vertex in vertices)
{
MapPoint.Location loc = vertex as MapPoint.Location;
}

Richard

bluefireball
03-15-2007, 06:01 PM
Thanks, Richard. I test it and your sample code works fine.

I fingured out the shape vertices is actual a COM object, I used following way to solve the problem. Silly but works. :-?

Object obj = shape.Vertices;
Type thisType = obj.GetType();
object[] args = new object[1];
int numEntries = (int)thisType.InvokeMember("Length", BindingFlags.GetProperty, null, obj, null);
if (numEntries > 0)
{
for (int j = 0; j < numEntries; j++)
{
args[0] = j;
objLoc[j] = (MapPoint.Location)thisType.InvokeMember("GetValue", BindingFlags.InvokeMethod, null, obj, args);
}
}