I am trying to add polyline in ArcMap by using tool for this I have written some code, but the polyline is not adding in the proper extent.

How can I change my code to draw a polyline?

public override void OnClick()
            IMxDocument mxd = m_application.Document as IMxDocument;

            ESRI.ArcGIS.Carto.IActiveView activeView =  mxd.ActiveView;
            IScreenDisplay sd = activeView.ScreenDisplay;

        private void DrawPolyline(ESRI.ArcGIS.Carto.IActiveView activeView)

            if (activeView == null)
            ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = activeView.ScreenDisplay;

            // Constant
            screenDisplay.StartDrawing(screenDisplay.hDC, (System.Int16)ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache); // Explicit Cast
            ESRI.ArcGIS.Display.IRgbColor rgbColor = new ESRI.ArcGIS.Display.RgbColorClass();
            rgbColor.Red = 255;

            ESRI.ArcGIS.Display.IColor color = rgbColor; // Implicit Cast
            ESRI.ArcGIS.Display.ISimpleLineSymbol simpleLineSymbol = new ESRI.ArcGIS.Display.SimpleLineSymbolClass();
            simpleLineSymbol.Color = color;

            ESRI.ArcGIS.Display.ISymbol symbol = (ESRI.ArcGIS.Display.ISymbol)simpleLineSymbol; // Explicit Cast
            ESRI.ArcGIS.Display.IRubberBand rubberBand = new ESRI.ArcGIS.Display.RubberLineClass();
            ESRI.ArcGIS.Geometry.IGeometry geometry = rubberBand.TrackNew(screenDisplay, symbol);

Your code is drawing the geometry to the screen display and as soon as that refreshes you will lose the display of it. It is unclear what you mean by "...not adding in the proper extent."? If you want your polyline that you have just drawn on the screen to be permanent you need to write it to a featureclass. If that is not what you mean and you simply want it to stay on the screen then you need to store it as a graphic in the IGraphicsContainer for the Map. Here is a blog that shows an example of adding a graphic using VB.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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