I'm trying to draw a custom polygon in Dynamic Display but its really not working at all. I can get it to work if I do this:

IPointCollection pc = seg.setRectangle( mapcontrol.map.extent.envelope) as IPointCollection; 

But I want a custom polygon. I tried this following code but I'm getting -2147220968

       IPoint p0 = new PointClass(); 
        IPoint p1 = new PointClass();
        IPoint p2 = new PointClass();
        p0.SpatialReference = gcs;
        p1.SpatialReference = gcs;
        p2.SpatialReference = gcs;

        p0.PutCoords(-94.569168d, 46.697493d);
        p1.PutCoords(-94.052811d, 46.711619d);
        p2.PutCoords(-94.51561d, 46.520131d);


        ILine line = new LineClass();
        ILine line2 = new LineClass();
        ILine line3 = new LineClass();

        line.SpatialReference = mapSP;
        line2.SpatialReference = mapSP;
        line3.SpatialReference = mapSP;

        line.FromPoint= p0; 
        line.ToPoint = p1;

        line2.FromPoint= p1; 
        line2.ToPoint = p2;

        line3.FromPoint= p2; 
        line3.ToPoint = p0;

        ISegmentCollection seg = new PolygonClass();
        seg.AddSegment(line as ISegment);
        seg.AddSegment(line2 as ISegment);
        seg.AddSegment(line3 as ISegment);
        pc = seg as IPointCollection;

                           dynamicSymbolProps.set_DynamicGlyph(esriDynamicSymbolType.esriDSymbolFill, fillGlyph);
catch (Exception ex)
  string m= ex.Message; 

1 Answer 1


Using the above code and adding the following will get it to work.

ITopologicalOperator toppy = seg as ITopologicalOperator;
IPointCollection4 pc4 = toppy as IPointCollection4;

dynamicSymbolProps.set_DynamicGlyph(esriDynamicSymbolType.esriDSymbolFill, fillGlyph);


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.