Disable or Reset a tool/button

1333
2
Jump to solution
07-01-2013 12:02 PM
LindseyWood
New Contributor III
Hi I am converting vb to vb.net COM session not add in... I have made add ins and never had this problem but for some reason the tool will not reset when the quit button is enabled the forms all close but the tool cross hair is still active.  I have tried every method I could find including .close/exit.application closed the forms but nothing to avail any suggestions would be much appreciated. Below is the function that is connected to the quit button and closes the forms only. I have been able to dispose it but then it would give me an error that you could not recreate something that has been previous disposed.. which is fine and the button and cross hairs are still there.


Protected Overrides Sub Finalize()
        MyBase.Finalize()
        'MyBase.OnMouseMove()
        MyBase.Deactivate()
    End Sub

I was hoping there was a function like this that I could call within the quit to finalize the session and reset the tool.

Thanks again! :confused:

Public Sub Quit_PI_Session()          Dim frmCollection As System.Windows.Forms.FormCollection         Dim frm As System.Windows.Forms.Form         Dim countFrm As Integer         Dim frmArr(2) As Object         Dim frmName As String          On Error GoTo ErrorHandler          'Reset global session variables         dblFrameLength = 0         dblFrameWidth = 0         intRollNumber = 0         intVRollNumber = 0         intRRollNumber = 0         intLRollNumber = 0         intFrameNumber = 0         intMethodListIndex = 0         intPhotoIndexListIndex = 0         intUnitsListIndex = 0         intNewFramesCheckboxCounter = 0         intFramesShapefileNamesCounter = 0         strPhotoIndexShapefileName = ""         strFramesShapefileName = ""          'End the current session         'Unload frmMethods         'Unload(frmRollFrame)'vb6         'Unload(frmRollFrameControls)'vb6         'Unload(frmPhotoIndex) 'vb6          frmCollection = System.Windows.Forms.Application.OpenForms          countFrm = frmCollection.Count - 1         For value As Integer = 0 To countFrm             frmArr(value) = frmCollection.Item(value)         Next          For value As Integer = 0 To frmArr.Length - 1             'frmArr(value).Hide()              'frmArr(value).Close()             'frmArr(value).Dispose()         Next          myFrmFrameFootPrinter.Close()         myFrmRollFrame.Close()         myFrmRollFrameControls.Close()          myFrmFrameFootPrinter = New frmFrameFootPrinter         myFrmRollFrame = New frmRollFrame         myFrmRollFrameControls = New frmRollFrameControls         myFrmRollFrameControls = Nothing          'myFrmFrameFootPrinter.Dispose()         'myFrmRollFrame.Dispose()         'myFrmRollFrameControls.Dispose()          Debug.Print("Closed all forms")          Exit Sub  'This message just happens when you move the mouse over and over again if this is enabled  'Public Overrides Sub OnMouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Integer, ByVal Y As Integer)     ''.NET deactivate tool     'If myFrmFrameFootPrinter.Visible = False Then     ' MsgBox("MyBase Deactivate")       'MyBase.Deactivate()     'MyBase.m_enabled = False      'End If End Sub  Private Sub cmdEndSession_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdEndSession.Click          'Reset global variables and Quit Photo Index Frame processing         Call Quit_PI_Session()          ESRI.ArcGIS.ADF.COMSupport.AOUninitialize.Shutdown()         'MyBase.m_deactivate = True         'MyBase.Close()         ' MyBase.Activate()         'MyBase.ResetMouseEventArgs()            'Application.Exit()         'Close()         'Environment.Exit(0)         'createPhotoFrames.Exit()         'm_application.Visible = False                   ' The user wants to exit the application. Close everything down.         'Application.Exit()       End Sub 
0 Kudos
1 Solution

Accepted Solutions
NeilClemmons
Regular Contributor III
If you have implemented ITool then clicking the button for your tool on the toolbar sets your tool to be ArcMap's current tool.  It will remain ArcMap's current tool until you set the current tool to something else in code or the user clicks another tool button on a toolbar.  Typically, when you no longer want your tool to be active you set IApplication.CurrentTool to Nothing.  You can also set it to another tool (like the default Select Element tool).  Note, your tool's implementation of ITool.Deactivate should return True if it doesn't already.

View solution in original post

0 Kudos
2 Replies
NeilClemmons
Regular Contributor III
If you have implemented ITool then clicking the button for your tool on the toolbar sets your tool to be ArcMap's current tool.  It will remain ArcMap's current tool until you set the current tool to something else in code or the user clicks another tool button on a toolbar.  Typically, when you no longer want your tool to be active you set IApplication.CurrentTool to Nothing.  You can also set it to another tool (like the default Select Element tool).  Note, your tool's implementation of ITool.Deactivate should return True if it doesn't already.
0 Kudos
LindseyWood
New Contributor III
Thank you soooo much! that was it perfect, oddly I saw reference to that but didn't try it, go figure. 😛
0 Kudos