I have found the solution to my own problem. I am new at using VB.net and I was trying to convert a program written in Visual Basic for Applications (VBA). In VBA, the following function call will allow you to run code when the tool is deactivated (my program was named MoveIt):
Private Function MoveIt_Deactivate() As Boolean
MoveSite_Deactivate = True
End Function
When I did a Google search for "arcgis deactivate tool", I found several programs with the following code:
Public Function Deactivate() As Boolean Implements ESRI.ArcGIS.SystemUI.ITool.Deactivate
' Deactivate the tool.
Return True
End Function
While this code may have worked in ArcGIS 8 and 9 (probably under VB 6), it no longer works in ArcGIS 10 and VB.net. However, the following program (which uses the function OnDeactivate) will work:
Public Class Tool1
Inherits ESRI.ArcGIS.Desktop.AddIns.Tool
Public Sub New()
' happens only when the tool is first loaded
MsgBox("Hello New")
End Sub
Protected Overrides Sub OnUpdate()
Enabled = My.ArcMap.Application IsNot Nothing
End Sub
Protected Overrides Sub OnActivate()
MyBase.OnActivate()
' happens every time the tool is activated
MsgBox("Hello Activate")
End Sub
Protected Overrides Sub OnMouseDown(ByVal arg As ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs)
MyBase.OnMouseDown(arg)
' Do something to show that the tool is working
MsgBox("OnMouseDown - another mouse down")
End Sub
Protected Overrides Function OnDeactivate() As Boolean
Dim Response As String
Response = MsgBox("Do You really want to leave?", MsgBoxStyle.YesNo, "OnDeactivate")
If Response = vbYes Then
OnDeactivate = True
Else
OnDeactivate = False
End If
End Function
End Class
If you want to try this code, first start Visual Basic (I am using Visual Basic 2008 Express Edition) and under File/New Project create a new ArcMap Desktop Add-in. Include a tool in the project (it will probably be named Tool1 or ArcGISAddin1). Open the vb code window for the tool and delete everything but the first line (the line that starts with Public Class...). Then copy all of the above code except for the first line and paste it in your project (this ensures that the name of the tool will match the name in the Config.esriaddinx window). Then press the F5 key to start debugging and enter ArcGIS.
In ArcGIS open a map and enter the Customize Mode. Find your tool in the Add-IN Controls category (under the Commands tab) and drag it to a tool bar. Exit Customize Mode and click on the tool to activate it.