AnsweredAssumed Answered

How to keep the graphics drawn on ScreenDisplay?

Question asked by huangs3 on Aug 15, 2012
Latest reply on Aug 16, 2012 by Neil
Hi Everybody:

    I am trying to make a tool that maintains an uneditable/unmovable polyline graphic on the screen display of the map. I found that the IScreenDisplay.DrawPolyline method can do a drawing, but the drawn graphic will disappear after a map refresh (caused by clicking refresh button, panning, etc.). Then  I tried to redraw the graphic every time the active view is refresh in the ViewRefreshed event handler. The result in the refresh is that the graphic got redrawn and then disappear again (same a s a flash).
    Following is the code in my BaseCommand class

        /// <summary>         /// Occurs when this command is clicked         /// </summary>         public override void OnClick()         {             m_drawn_graphics.Clear();              // findout which the feature selected              IActiveView activeView = (m_application.Document as IMxDocument).ActivatedView;             IMap map = activeView.FocusMap;             IEnumFeature enumFeature = (IEnumFeature)map.FeatureSelection; // Explicit Cast             enumFeature.Reset();             IFeature feature = null;             while (null!=(feature = enumFeature.Next()))             {                 if (feature.Shape is IPolyline)                 {                     m_drawn_graphics.Add(feature.ShapeCopy as IPolyline);                 }             }              (activeView as IActiveViewEvents_Event).ViewRefreshed -= drawfeature_ViewRefreshed;             (activeView as IActiveViewEvents_Event).ViewRefreshed += drawfeature_ViewRefreshed;                          activeView.Refresh();         }          void drawfeature_ViewRefreshed(IActiveView view, esriViewDrawPhase phase, object Data, IEnvelope envelope)         {             IActiveView activeView = view;             IScreenDisplay screenDisplay = activeView.ScreenDisplay;             screenDisplay.StartDrawing(screenDisplay.hDC, (Int16)esriScreenCache.esriNoScreenCache);             IRgbColor lineHighlightColor = new RgbColorClass { Red = 0, Green = 0, Blue = 255 };             ISimpleLineSymbol s = new SimpleLineSymbolClass();             s.Color = lineHighlightColor;             s.Style = esriSimpleLineStyle.esriSLSSolid;             s.Width = 5;             screenDisplay.SetSymbol(s as ISymbol);             foreach (IPolyline l in m_drawn_graphics)             {                 screenDisplay.DrawPolyline(l);             }             screenDisplay.FinishDrawing();         }

Why would this code work as expected? Does it mean the removal of the drawn graphic happens after the event is fired?
Thank you!