Inherit this abstract class to create a tool. Tools are similar to buttons but they also require interaction with the application's display.

Namespace:  ESRI.ArcGIS.Desktop.AddIns

Assembly:  ESRI.ArcGIS.Desktop.Addins (in ESRI.ArcGIS.Desktop.Addins.dll) Version: 10.0.0.0 (10.0.0.0)

Syntax

C#
public abstract class Tool : IDisposable
Visual Basic (Declaration)
Public MustInherit Class Tool _
	Implements IDisposable
Visual C++
public ref class Tool abstract : IDisposable

Remarks

The simplest way to create a new Tool is to use the templates provided in the ArcObjects SDK for .NET. For step by step instructions on creating a new Tool using these templates, see the Creating custom UI walkthrough.

Examples

The code below shows the implementation of select features by line tool.
CopyC#
public class SelectByLineTool : ESRI.ArcGIS.Desktop.AddIns.Tool
{
  bool m_isMouseDown = false;
  ESRI.ArcGIS.Display.INewLineFeedback m_lineFeedback;

  public SelectByLineTool()
  {
  }

  protected override void OnKeyDown(ESRI.ArcGIS.Desktop.AddIns.Tool.KeyEventArgs arg)
  {
    if (arg.ModifierKeys == (System.Windows.Forms.Keys.Shift & System.Windows.Forms.Keys.Control))
      System.Windows.Forms.MessageBox.Show("Shift+Control");
  }
  protected override void OnMouseDown(MouseEventArgs arg)
  {
    IMxDocument mxDoc = ArcMap.Document;
    IActiveView activeView = mxDoc.FocusMap as IActiveView;
    IPoint point = activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(arg.X, arg.Y) as IPoint;

    if (m_lineFeedback == null)
    {
      m_lineFeedback = new ESRI.ArcGIS.Display.NewLineFeedback();
      m_lineFeedback.Display = activeView.ScreenDisplay;
      m_lineFeedback.Start(point);
    }
    else
    {
      m_lineFeedback.AddPoint(point);
    }

    m_isMouseDown = true;
  }

  protected override void OnDoubleClick()
  {
    IMxDocument mxDoc = ArcMap.Document;
    IActiveView activeView = mxDoc.FocusMap as IActiveView;

    activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);

    IPolyline polyline;

    if (m_lineFeedback != null)
    {
      polyline = m_lineFeedback.Stop();
      if (polyline != null)
        mxDoc.FocusMap.SelectByShape(polyline, null, false);
    }


    activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);

    m_lineFeedback = null;
    m_isMouseDown = false;
  }

  protected override void OnMouseMove(MouseEventArgs arg)
  {
    if (!m_isMouseDown) return;

    IMxDocument mxDoc = ArcMap.Document;
    IActiveView activeView = mxDoc.FocusMap as IActiveView;

    IPoint point = activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(arg.X, arg.Y) as IPoint;
    m_lineFeedback.MoveTo(point);
  }

  protected override void OnUpdate()
  {
    this.Enabled = SelectionExtension.IsExtensionEnabled;
  }
}
CopyVB.NET
Public Class SelectByLineTool
  Inherits ESRI.ArcGIS.Desktop.AddIns.Tool
  Private m_isMouseDown As Boolean = False
  Private m_lineFeedback As ESRI.ArcGIS.Display.INewLineFeedback

  Public Sub New()
  End Sub

  Protected Overloads Overrides Sub OnKeyDown(ByVal arg As ESRI.ArcGIS.Desktop.AddIns.Tool.KeyEventArgs)
    If arg.ModifierKeys = (System.Windows.Forms.Keys.Shift And System.Windows.Forms.Keys.Control) Then
      System.Windows.Forms.MessageBox.Show("Shift+Control")
    End If
  End Sub
  Protected Overloads Overrides Sub OnMouseDown(ByVal arg As MouseEventArgs)
    Dim mxDoc As IMxDocument = ArcMap.Document
    Dim activeView As IActiveView = TryCast(mxDoc.FocusMap, IActiveView)
    Dim point As IPoint = TryCast(activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(arg.X, arg.Y), IPoint)

    If m_lineFeedback Is Nothing Then
      m_lineFeedback = New ESRI.ArcGIS.Display.NewLineFeedback()
      m_lineFeedback.Display = activeView.ScreenDisplay
      m_lineFeedback.Start(point)
    Else
      m_lineFeedback.AddPoint(point)
    End If

    m_isMouseDown = True
  End Sub

  Protected Overloads Overrides Sub OnDoubleClick()
    Dim mxDoc As IMxDocument = ArcMap.Document
    Dim activeView As IActiveView = TryCast(mxDoc.FocusMap, IActiveView)

    activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, Nothing, Nothing)

    Dim polyline As IPolyline

    If m_lineFeedback IsNot Nothing Then
      polyline = m_lineFeedback.[Stop]()
      If polyline IsNot Nothing Then
        mxDoc.FocusMap.SelectByShape(polyline, Nothing, False)
      End If
    End If


    activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, Nothing, Nothing)

    m_lineFeedback = Nothing
    m_isMouseDown = False
  End Sub

  Protected Overloads Overrides Sub OnMouseMove(ByVal arg As MouseEventArgs)
    If Not m_isMouseDown Then
      Exit Sub
    End If

    Dim mxDoc As IMxDocument = ArcMap.Document
    Dim activeView As IActiveView = TryCast(mxDoc.FocusMap, IActiveView)

    Dim point As IPoint = TryCast(activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(arg.X, arg.Y), IPoint)
    m_lineFeedback.MoveTo(point)
  End Sub

  Protected Overloads Overrides Sub OnUpdate()
    Me.Enabled = SelectionExtension.IsExtensionEnabled
  End Sub
End Class

Inheritance Hierarchy

System..::.Object

  ESRI.ArcGIS.Desktop.AddIns..::.Tool

See Also