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


Get Polyline From Mouse Clicks Snippet (ArcObjects .NET 10.5 SDK)
ArcObjects Library Reference

Get Polyline From Mouse Clicks Snippet

Create a polyline geometry object using the RubberBand.TrackNew method when a user click the mouse on the map control.

[C#]
///<summary>
///Create a polyline geometry object using the RubberBand.TrackNew method when a user click the mouse on the map control. 
///</summary>
///<param name="activeView">An ESRI.ArcGIS.Carto.IActiveView interface that will user will interace with to draw a polyline.</param>
///<returns>An ESRI.ArcGIS.Geometry.IPolyline interface that is the polyline the user drew</returns>
///<remarks>Double click the left mouse button to end tracking the polyline.</remarks>
public ESRI.ArcGIS.Geometry.IPolyline GetPolylineFromMouseClicks(ESRI.ArcGIS.Carto.IActiveView activeView)
{

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

  ESRI.ArcGIS.Display.IRubberBand rubberBand=new ESRI.ArcGIS.Display.RubberLineClass();
  ESRI.ArcGIS.Geometry.IGeometry geometry=rubberBand.TrackNew(screenDisplay, null);

  ESRI.ArcGIS.Geometry.IPolyline polyline=(ESRI.ArcGIS.Geometry.IPolyline)geometry;

  return polyline;

}
[Visual Basic .NET]
'''<summary>
'''Create a polyline geometry object using the RubberBand.TrackNew method when a user click the mouse on the map control. 
'''</summary>
'''<param name="activeView">An ESRI.ArcGIS.Carto.IActiveView interface that will user will interace with to draw a polyline.</param>
'''<returns>An ESRI.ArcGIS.Geometry.IPolyline interface that is the polyline the user drew</returns>
'''<remarks>Double click the left mouse button to end tracking the polyline.</remarks>
Public Function GetPolylineFromMouseClicks(ByVal activeView As ESRI.ArcGIS.Carto.IActiveView) As ESRI.ArcGIS.Geometry.IPolyline

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

  Dim rubberBand As ESRI.ArcGIS.Display.IRubberBand=New ESRI.ArcGIS.Display.RubberLineClass
  Dim geometry As ESRI.ArcGIS.Geometry.IGeometry=rubberBand.TrackNew(screenDisplay, Nothing)

  Dim polyline As ESRI.ArcGIS.Geometry.IPolyline=CType(geometry, ESRI.ArcGIS.Geometry.IPolyline)

  Return polyline

End Function

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