<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Controlled Deactivation of Add-In Tool using VB.net in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/controlled-deactivation-of-add-in-tool-using-vb/m-p/578824#M15624</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am using Visual Basic 2008 Express to develop a tool for correcting the locations of features. The user first selects the feature, then activates the tool and clicks on the correct location. The tool then starts edit mode and relocates the feature. At this point I want ArcMap to remain in edit mode until the user deactivates the tool, after which the user will be asked if he wants to save his edits. My problem is that I cannot figure out how to acquire control when the tool is deactivated. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The following simplified code &lt;/SPAN&gt;&lt;SPAN style="color: #222222; font-family: Verdana;"&gt;illustrates &lt;/SPAN&gt;&lt;SPAN&gt;the approach that I am trying to use. However, VB2008 gives the following error: "&lt;/SPAN&gt;&lt;STRONG&gt;Interface 'ESRI.ArcGIS.SystemUI.ITool' is not implemented by this class"&lt;/STRONG&gt;&lt;SPAN&gt;. Can anyone tell me what I am doing wrong?&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Public Class MoveIt&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Inherits ESRI.ArcGIS.Desktop.AddIns.Tool&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Public Sub New()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;MsgBox("Hello")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;End Sub&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Protected Overrides Sub OnUpdate()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Enabled = My.ArcMap.Application IsNot Nothing&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;End Sub&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Public Function Deactivate() As Boolean Implements &lt;/SPAN&gt;&lt;SPAN style="text-decoration:underline;"&gt;ESRI.ArcGIS.SystemUI.ITool.Deactivate&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;MsgBox("GoodBy")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Deactivate = True&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;End Function&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;End Class&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 16 Mar 2012 16:59:14 GMT</pubDate>
    <dc:creator>DavidFroehlich</dc:creator>
    <dc:date>2012-03-16T16:59:14Z</dc:date>
    <item>
      <title>Controlled Deactivation of Add-In Tool using VB.net</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/controlled-deactivation-of-add-in-tool-using-vb/m-p/578824#M15624</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am using Visual Basic 2008 Express to develop a tool for correcting the locations of features. The user first selects the feature, then activates the tool and clicks on the correct location. The tool then starts edit mode and relocates the feature. At this point I want ArcMap to remain in edit mode until the user deactivates the tool, after which the user will be asked if he wants to save his edits. My problem is that I cannot figure out how to acquire control when the tool is deactivated. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The following simplified code &lt;/SPAN&gt;&lt;SPAN style="color: #222222; font-family: Verdana;"&gt;illustrates &lt;/SPAN&gt;&lt;SPAN&gt;the approach that I am trying to use. However, VB2008 gives the following error: "&lt;/SPAN&gt;&lt;STRONG&gt;Interface 'ESRI.ArcGIS.SystemUI.ITool' is not implemented by this class"&lt;/STRONG&gt;&lt;SPAN&gt;. Can anyone tell me what I am doing wrong?&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Public Class MoveIt&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Inherits ESRI.ArcGIS.Desktop.AddIns.Tool&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Public Sub New()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;MsgBox("Hello")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;End Sub&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Protected Overrides Sub OnUpdate()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Enabled = My.ArcMap.Application IsNot Nothing&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;End Sub&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Public Function Deactivate() As Boolean Implements &lt;/SPAN&gt;&lt;SPAN style="text-decoration:underline;"&gt;ESRI.ArcGIS.SystemUI.ITool.Deactivate&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;MsgBox("GoodBy")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Deactivate = True&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;End Function&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;End Class&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 16 Mar 2012 16:59:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/controlled-deactivation-of-add-in-tool-using-vb/m-p/578824#M15624</guid>
      <dc:creator>DavidFroehlich</dc:creator>
      <dc:date>2012-03-16T16:59:14Z</dc:date>
    </item>
    <item>
      <title>Re: Controlled Deactivation of Add-In Tool using VB.net</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/controlled-deactivation-of-add-in-tool-using-vb/m-p/578825#M15625</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;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):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="color:#0000ff;"&gt;Private Function MoveIt_Deactivate() As Boolean&lt;BR /&gt;MoveSite_Deactivate = True&lt;BR /&gt;End Function&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;When I did a Google search for "arcgis deactivate tool", I found several programs with the following code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="color:#0000ff;"&gt;Public Function Deactivate() As Boolean Implements ESRI.ArcGIS.SystemUI.ITool.Deactivate&lt;BR /&gt;' Deactivate the tool. &lt;BR /&gt;Return True&lt;BR /&gt;End Function &lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;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:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="color:#0000ff;"&gt;Public Class Tool1&lt;BR /&gt;Inherits ESRI.ArcGIS.Desktop.AddIns.Tool&lt;BR /&gt;&lt;BR /&gt;Public Sub New()&lt;BR /&gt;' happens only when the tool is first loaded&lt;BR /&gt;MsgBox("Hello New")&lt;BR /&gt;End Sub&lt;BR /&gt;&lt;BR /&gt;Protected Overrides Sub OnUpdate()&lt;BR /&gt;Enabled = My.ArcMap.Application IsNot Nothing&lt;BR /&gt;End Sub&lt;BR /&gt;&lt;BR /&gt;Protected Overrides Sub OnActivate()&lt;BR /&gt;MyBase.OnActivate()&lt;BR /&gt;' happens every time the tool is activated&lt;BR /&gt;MsgBox("Hello Activate")&lt;BR /&gt;End Sub&lt;BR /&gt;&lt;BR /&gt;Protected Overrides Sub OnMouseDown(ByVal arg As ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs)&lt;BR /&gt;MyBase.OnMouseDown(arg)&lt;BR /&gt;' Do something to show that the tool is working&lt;BR /&gt;MsgBox("OnMouseDown - another mouse down")&lt;BR /&gt;End Sub&lt;BR /&gt;&lt;BR /&gt;Protected Overrides Function OnDeactivate() As Boolean&lt;BR /&gt;Dim Response As String&lt;BR /&gt;Response = MsgBox("Do You really want to leave?", MsgBoxStyle.YesNo, "OnDeactivate")&lt;BR /&gt;If Response = vbYes Then&lt;BR /&gt;OnDeactivate = True&lt;BR /&gt;Else&lt;BR /&gt;OnDeactivate = False&lt;BR /&gt;End If&lt;BR /&gt;End Function&lt;BR /&gt;&lt;BR /&gt;End Class&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;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. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Mar 2012 16:36:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/controlled-deactivation-of-add-in-tool-using-vb/m-p/578825#M15625</guid>
      <dc:creator>DavidFroehlich</dc:creator>
      <dc:date>2012-03-21T16:36:08Z</dc:date>
    </item>
    <item>
      <title>Re: Controlled Deactivation of Add-In Tool using VB.net</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/controlled-deactivation-of-add-in-tool-using-vb/m-p/578826#M15626</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I wanted to thank you for this. I noticed there are a lot of things not documented, and this will help a lot of people. Good job!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 May 2012 02:33:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/controlled-deactivation-of-add-in-tool-using-vb/m-p/578826#M15626</guid>
      <dc:creator>LoganLehman</dc:creator>
      <dc:date>2012-05-11T02:33:15Z</dc:date>
    </item>
    <item>
      <title>Re: Controlled Deactivation of Add-In Tool using VB.net</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/controlled-deactivation-of-add-in-tool-using-vb/m-p/578827#M15627</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;thank you for the highlight of the Deactivation problem.&amp;nbsp; it helped me fix it.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Protected Function OnDeactivate() As Boolean
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'Do other units of work.



&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Me.m_deactivate = True
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Me.m_enabled = False
&amp;nbsp;&amp;nbsp;&amp;nbsp; End Function
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;the compiler did not like the over ride word and the above function works.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;thanks for your help.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:52:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/controlled-deactivation-of-add-in-tool-using-vb/m-p/578827#M15627</guid>
      <dc:creator>Ravichandran_M_Kaushika</dc:creator>
      <dc:date>2021-12-12T00:52:53Z</dc:date>
    </item>
  </channel>
</rss>

