Change Mouse Cursor on Tool

6723
6
09-29-2011 08:47 AM
Highlighted
New Contributor
I can't seem to find exactly what I need here.  I am in VB .NET 2010 writing an Add In for ArcMap.  I have a tool that a user clicks then selects a polygon on the map view. After the tool is clicked, I would like to change the cursor to a crosshair.  Either the code I am using is wrong, or I am placing it in the wrong sub or function of the tool.

I have tried
        Dim pMouse As IMouseCursor = New MouseCursor
        pMouse.SetCursor(esriSystemMouseCursor.esriSystemMouseCursorCrosshair)
and
        Windows.Forms.Cursor.Current = Cursors.Cross

both initiated from the OnActivate() sub.  Any help would be great.  Thanks.
Reply
0 Kudos
6 Replies
Highlighted
New Contributor III
this is in C#
override Tool Cursor method and

return Cursors.Cross.Handle.ToInt32();
Reply
0 Kudos
Highlighted
Regular Contributor II
this is in C#
override Tool Cursor method and

return Cursors.Cross.Handle.ToInt32();


Can you elaborate on this?
How does this work with an Inherits Addin?

Property CURSOR can not be declared 'overrides' because it does not override a property in a base class.
Reply
0 Kudos
Highlighted
Regular Contributor II
Jeffry

You can use custom Cursor of any sort using a TOOL addin rather than a button (if that is what you are using), and referencing the embedded .cur file within the config.esriaddinx xml file.

   <Tool id="Microsoft_ArcMapAddin1_Jeffry_Class" class="Jeffry_Class" message="This is the description" caption="Jeffry" tip="Cursor Tooltip" category="AddInControls" image="Images\Jeffry_Class.png" cursor="Images\JeffryCustomCursor.cur">


Just remember to to have the build action of your cursor : AddInContent, rather than embedding.

Within the Class referenced to in the xml file... you can then do a mousedown for example
  'OnMouse down
    Protected Overrides Sub OnMouseDown(ByVal arg As ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs)
        MyBase.OnMouseDown(arg)


        'Code here on Mouse down

    End Sub


What is stated above is through ITool, through IToolDef, not Addin method.

   
    
           'for Cursor  - create the cursor
            m_Cursor = New System.Windows.Forms.Cursor(Me.GetType.Assembly.GetManifestResourceStream("FocusToolsToolbar.CrosshairCursor.cur"))
            If Not m_Cursor Is Nothing Then
                mh_Cursor = m_Cursor.Handle
            End If


Public ReadOnly Property cursor() As Integer Implements ESRI.ArcGIS.SystemUI.ITool.Cursor
            Get
                Return mh_Cursor.ToInt32
            End Get
        End Property
Highlighted
New Contributor III

Can  you elaborate on how this can be implemented?  I am trying to change my tool cursor after click events, from one cursor to another, depending on the current click's function.  I am currently only able to set the cursor to default Window.Forms.Cursors.

Reply
0 Kudos
Highlighted
Occasional Contributor
I had much better success using

OnActivate()
  System.Windows.Forms.Cursor.Current = Cursors.WaitCursor

   'do stuff
    My.ArcMap.Application.CurrentTool = Nothing
End Sub
Reply
0 Kudos
Highlighted
Regular Contributor II
I had much better success using

OnActivate()
  System.Windows.Forms.Cursor.Current = Cursors.WaitCursor

   'do stuff
    My.ArcMap.Application.CurrentTool = Nothing
End Sub


This is not correct, this is changing the windows cursor, meaning your cursor would change for all places on the screen regardless of location. Using what I had done, means the cursor changes ONLY when you are in the Map Window itself. Moving the cursor out of the map window to a toolbar changes back to the proper Pointer.
Reply
0 Kudos