I draw a polygon on button click which to highlight a feature. Then I need to refresh the ActiveView to show the new polygon. This lines do work:
mapControl.ActiveView.ScreenDisplay.StartDrawing(StartDrawing(mapControl.ActiveView.ScreenDisplay.hDC, (System.Int16)ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache);
mapControl.ActiveView.ScreenDisplay.DrawPolygon(feature.Shape);
mapControl.ActiveView.ScreenDisplay.FinishDrawing();
mapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewAll, feature.Extent, null);
But it always reloads every layer. I tried nearly all ways of calling PartialRefresh with other esriViewDrawPhase but none of them did show the new polygon.
Is there a better solution than to redraw with esriViewDrawPhase.esriViewAll?
Update
I used an ILayerExtensionDraw.AfterDraw to test the draw phases and the AfterDraw only gets hit for PartialRefresh() with esriViewAll. The extension is added to all layers in MapControl.Layers. I expected that it gets hit everytime? On which layer does mapControl.ActiveView.ScreenDisplay.DrawPolygon(feature.Shape); draw so that the AfterDraw isn't even raised?
Answer
Thanks to Kirk here is the solution, which shows the new added graphic without reloading any layer.
IGraphicsContainer con = _mapControl.Map as IGraphicsContainer;
if (con != null)
{
IFillShapeElement fillShapeElement = new PolygonElementClass();
fillShapeElement.Symbol = fillSymbol;
IElement element = (IElement)fillShapeElement;
element.Geometry = feature.Shape;
con.DeleteAllElements();
con.AddElement(element, 0);
_mapControl.ActiveView.ScreenDisplay.Invalidate(feature.Extent, true, _mapControl.ActiveView.get_ScreenCacheID(esriViewDrawPhase.esriViewGraphics, null));
}
esriScreenCache.esriNoScreenCache), you should not need to refresh at all. In fact refreshing would cause the graphic to disappear. Have you tried without thePartialRefreshline? – blah238 Jan 30 '12 at 19:55esriViewAllworked for me. – gumo Jan 31 '12 at 8:30