In the code below btnMapTool is the button on my form I want to launch the Tool. Tool1 is the name of the tool. Hope this helps.
Private Sub btnMapTool_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMapTool.Click
Dim pUID As New ESRI.ArcGIS.esriSystem.UID
Dim pCommandItem As ESRI.ArcGIS.Framework.ICommandItem
pUID.Value = My.ThisAddIn.IDs.Tool1
pCommandItem = m_app.Document.CommandBars.Find(pUID, False, False)
m_app.CurrentTool = pCommandItem
End Sub
'************Below is the top portion of my Tool1 class.
Imports ESRI.ArcGIS.esriSystem
Imports ESRI.ArcGIS.Geometry
Imports ESRI.ArcGIS.Display
Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.Geodatabase
Imports System.Xml.Linq
Imports System.Windows.Forms
Imports ESRI.ArcGIS.ArcMapUI
Public Class Tool1
Inherits ESRI.ArcGIS.Desktop.AddIns.Tool
Private Shared s_tool As Tool1
Private m_app As ESRI.ArcGIS.Framework.IApplication = ArcMapAddin2.My.ArcMap.Application
Private MxDoc As ESRI.ArcGIS.ArcMapUI.IMxDocument = ArcMapAddin2.My.ArcMap.Document
Public Sub New()
s_tool = Me
End Sub
Friend Shared Function GetTool() As Tool1
If s_tool Is Nothing Then
Dim toolID As UID = New UIDClass()
toolID.Value = ArcMapAddin2.My.IDs.Tool1
ArcMapAddin2.My.ArcMap.Application.FindExtensionByCLSID(toolID)
End If
Return s_tool
End Function
Protected Overrides Sub OnUpdate()
Enabled = My.ArcMap.Application IsNot Nothing
End Sub
Protected Overrides Sub OnMouseDown(ByVal arg As ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs)
MyBase.OnMouseDown(arg)
'Get the active view from the ArcMap static class.
Dim activeView As IActiveView = My.ArcMap.Document.ActiveView
'****************************************************************************************************
'Get the X, Y coordinate from the point the tool was clicked
Dim point As IPoint
Dim DisplayTransform As IDisplayTransformation
point = New ESRI.ArcGIS.Geometry.Point
DisplayTransform = MxDoc.ActiveView.ScreenDisplay.DisplayTransformation
point = DisplayTransform.ToMapPoint(arg.X, arg.Y)
point.PutCoords(point.X, point.Y)
'MsgBox("x = " & point.X & " y = " & point.Y)
'*************More Code for the tool goes here
End Sub