This document is archived and information here might be outdated.  Recommended version.


Draw Polyline Using Input Geometry Snippet (ArcObjects .NET 10.4 SDK)
ArcObjects Library Reference

Draw Polyline Using Input Geometry Snippet

Draws a polyline on the screen in the ActiveView.

[C#]
///<summary>
///Draws a polyline on the screen in the ActiveView.
///</summary>
///<param name="activeView">An ESRI.ArcGIS.Carto.IActiveView interface to recieve the graphic.</param>
///<param name="geometry">An ESRI.ArcGIS.Geometry.IPolyline interface that will be drawn.</param>
///<param name="rgbColor">An ESRI.ArcGIS.Display.IRgbColor interface that will be the color to draw the geometry.</param>
///<remarks>The polyline drawn is a temporary graphic and will disappear at the next map refresh.</remarks>
public void DrawPolylineUsingInputGeometry(ESRI.ArcGIS.Carto.IActiveView activeView, ESRI.ArcGIS.Geometry.IPolyline geometry, ESRI.ArcGIS.Display.IRgbColor rgbColor)
{

  if (activeView == null)
  {
    return;
  }

  ESRI.ArcGIS.Display.IScreenDisplay screenDisplay=activeView.ScreenDisplay;

  // Constant
  screenDisplay.StartDrawing(screenDisplay.hDC, System.Convert.ToInt16(ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache));

  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
  screenDisplay.SetSymbol(symbol);
  screenDisplay.DrawPolyline(geometry);
  screenDisplay.FinishDrawing();

}
[Visual Basic .NET]
'''<summary>
'''Draws a polyline on the screen in the ActiveView.
'''</summary>
'''<param name="activeView">An ESRI.ArcGIS.Carto.IActiveView interface to recieve the graphic.</param>
'''<param name="geometry">An ESRI.ArcGIS.Geometry.IPolyline interface that will be drawn.</param>
'''<param name="rgbColor">An ESRI.ArcGIS.Display.IRgbColor interface that will be the color to draw the geometry.</param>
'''<remarks>The polyline drawn is a temporary graphic and will disappear at the next map refresh.</remarks>
Public Sub DrawPolylineUsingInputGeometry(ByVal activeView As ESRI.ArcGIS.Carto.IActiveView, ByVal geometry As ESRI.ArcGIS.Geometry.IPolyline, ByVal rgbColor As ESRI.ArcGIS.Display.IRgbColor)

  If activeView Is Nothing Then
    Return
  End If

  Dim screenDisplay As ESRI.ArcGIS.Display.IScreenDisplay=activeView.ScreenDisplay

  ' Constant
  screenDisplay.StartDrawing(screenDisplay.hDC, CShort(ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache))

  Dim color As ESRI.ArcGIS.Display.IColor=rgbColor ' Implicit Cast
  Dim simpleLineSymbol As ESRI.ArcGIS.Display.ISimpleLineSymbol=New ESRI.ArcGIS.Display.SimpleLineSymbolClass
  simpleLineSymbol.Color=color

  Dim symbol As ESRI.ArcGIS.Display.ISymbol=CType(simpleLineSymbol, ESRI.ArcGIS.Display.ISymbol) ' Explicit Cast
  screenDisplay.SetSymbol(symbol)
  screenDisplay.DrawPolyline(geometry)
  screenDisplay.FinishDrawing()

End Sub

Additional Requirements
  • The code in this document requires the following References added to the Visual Studio project:
  • ESRI.ArcGIS.Carto
  • ESRI.ArcGIS.Display
  • ESRI.ArcGIS.Geometry
  • ESRI.ArcGIS.System