Setting the mouse cursor in a custom application

906
3
Jump to solution
03-05-2012 12:39 AM
Highlighted
Occasional Contributor
Hi,
I'm writing a custom application (DotNet 4.0, Windows Forms) that uses ArcObjects SDK in order to achieve custom mapping tool functionality.
The map control in instantiated, initialized and docked within the main form of the application. It correctly loads and displays maps and other features tested this far.

There is a problem I am experiencing with loading the mouse cursor.
Using the mouse down and mouse up events of the main map control, I've added code to set the mouse cursor accordingly:


    void axMapControl_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
    {
      int rightMouseButton = 2;
      if (e.button == rightMouseButton)
      {
        //Cursor = Cursors.NoMove2D;

        IMouseCursor appCursor = new MouseCursorClass();
        appCursor.SetCursor(2);
      }
    }

    void axMapControl_OnMouseUp(object sender, IMapControlEvents2_OnMouseUpEvent e)
    {
      //Cursor = Cursors.Default;
     
      IMouseCursor appCursor = new MouseCursorClass();
      appCursor.SetCursor(3);
    }


If I run the mouse down code above it throws an exception :
"Retrieving the COM class factory for component with CLSID {DCAB4344-69D0-492A-9468-9A89A8E9B571} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))."
NOTE - I have only ArcEngine installed (not ArcDesktop, or any of the other ESRI applications). Is this the problem? - Does ESRI.ArcGIS.Framework only apply to ArcView/ ArcMap/ ArcDesktop?) If yes, how should I be setting the cursor through arc objects SDK for a custom mapping application?

(Another test : Setting the cursor directly using DotNet (see commented code above) works correctly)
Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Occasional Contributor
It appears that the MousePointer accessor is actually the solution (works for ArcEngine).

      mapControl.MousePointer = esriControlsMousePointer.esriPointerCrosshair;


However, another problem was introduced which should probably be tackled in another thread:
When mapControl.ActiveView.ScreenDisplay.TrackPan(); is called, then the mouse up event no longer fires (even if the second pan mode has not yet engaged).

This means the following code becomes useless (it is only called after a double mouse click):

    void axMapControl_OnMouseUp(object sender, IMapControlEvents2_OnMouseUpEvent e)     {       mapControl.MousePointer = esriControlsMousePointer.esriPointerArrow;     }

View solution in original post

Reply
0 Kudos
3 Replies
Highlighted
Regular Contributor II
"Product Availability
Available with ArcGIS Desktop."

http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//0023000000rr000000

Mouse cursor is only for desktop applications not engine.  If you are developing in .net, you can use a .net mouse cursor on a form.
Reply
0 Kudos
Highlighted
Occasional Contributor
Thanks Alexander,
I scratched around some more and found the MousePointer property (supported for ArcEngine) which works for the basic case:

    
    void axMapControl_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
    {
      axMapControl.MousePointer = esriControlsMousePointer.esriPointerCrosshair;
    }


    void axMapControl_OnMouseUp(object sender, IMapControlEvents2_OnMouseUpEvent e)
    {
      axMapControl.MousePointer = esriControlsMousePointer.esriPointerHand;
    }


However, the moment I add something like panning, ArcObjects seems to go and override the pointer again in the background :


    void axMapControl_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
    {
      axMapControl.MousePointer = esriControlsMousePointer.esriPointerCrosshair;
      axMapControl.ActiveView.ScreenDisplay.TrackPan();
    }


    void axMapControl_OnMouseUp(object sender, IMapControlEvents2_OnMouseUpEvent e)
    {
      axMapControl.MousePointer = esriControlsMousePointer.esriPointerHand;
    }


I suspect that there is an 'afterpan' event which is possibly called after OnMouseUp, and overrides the mouse pointer?
I've noticed the 'PanStart' and 'PanStop' methods, but I really would like to use the TrackPan feature...
Another solution would be to fire a timer on mouse up, which then checks the mouse pointer and sets it back - but that's messy 😐

More info : Once TrackPan has been called in response to a mouse down event, and the user continues to hold down the right mouse button (for +-1.5 seconds) then ArcObjects will enter a different 'panning mode' which automatically displays the relevant mouse panning cursor depending on the mouse movement. Unfortunately this is not as responsive as the initial panning mode though. This mode may be acceptable if the user continues to pan - and thus enters a move flexible panning mode but the problem with the original mouse cursor still remains.

Any other ideas?
Reply
0 Kudos
Highlighted
Occasional Contributor
It appears that the MousePointer accessor is actually the solution (works for ArcEngine).

      mapControl.MousePointer = esriControlsMousePointer.esriPointerCrosshair;


However, another problem was introduced which should probably be tackled in another thread:
When mapControl.ActiveView.ScreenDisplay.TrackPan(); is called, then the mouse up event no longer fires (even if the second pan mode has not yet engaged).

This means the following code becomes useless (it is only called after a double mouse click):

    void axMapControl_OnMouseUp(object sender, IMapControlEvents2_OnMouseUpEvent e)     {       mapControl.MousePointer = esriControlsMousePointer.esriPointerArrow;     }

View solution in original post

Reply
0 Kudos