Select to view content in your preferred language

How to implement OnMouseClick Event in ArcMap AddIn C#

4483
8
07-18-2011 06:24 AM
SebastianKrings
Frequent Contributor
Hi,

I just want to implement a onMouseClick event. When the specific Add-In is clicked, I want to change the mouseCurser and the user shall click again but now on the map.
The coordinates of the click on the map are which I want to read and work with.

I found the mapcontrol where I may can change the curser, but didnt find the event handling.

Thanks for help!
0 Kudos
8 Replies
BerendVeldkamp
Frequent Contributor
Make sure your add-in contains a 'tool' (not a button). You can set the tool's cursor, this is used when the pointer is over the map.

There's no Click event, but you can override OnMouseDown and OnMouseUp instead.

For example:
public class Tool1 : ESRI.ArcGIS.Desktop.AddIns.Tool     
{
    public Tool1()         
    {             
        this.Cursor = Cursors.SizeAll;         
    }
    
    protected override void OnMouseUp(MouseEventArgs arg)         
    {             
        base.OnMouseUp(arg);               
        System.Diagnostics.Debug.WriteLine(arg.X + " " + arg.Y);           
    }
}
0 Kudos
SebastianKrings
Frequent Contributor
hey, thanks for your answer

but I have a question to this to understand anything right:

when ist the on mouse down event called? everytime when going down or just after clicking the tool's button? does ist also activate after using an other function or will it then be disabled until the tool's button is first clicked again to activate the on mouse down event?
0 Kudos
BerendVeldkamp
Frequent Contributor
The MouseDown event is called when a user presses the mouse on the mapcontrol, not when you click the toolbutton (in that case, OnActivate is called). The events will be called until another tool is selected. The tool can of course deactive itself by setting the Application's CurrentTool to something else.
0 Kudos
SebastianKrings
Frequent Contributor
hey

so could it be possible that more than one tool overrides the onmousedown event and every time when i click on the map control (without clickin one of the tools before) every on mouse down event which has overridden is called?

because of that i have to query the activation status of every overridden onmousedown, havnt i?
so maybe make a if statement if(this.isActivated()){...}
and on elseway do nothing, i'm right?

thanks
0 Kudos
BerendVeldkamp
Frequent Contributor
No, only one single tool can be active at a time, and that is the tool that receives mouse messages.
0 Kudos
SebastianKrings
Frequent Contributor
ah ok

but how does arc map know which tool's onmouse down to call when havin two or more tools?
0 Kudos
BerendVeldkamp
Frequent Contributor
Because only one tool can be active at a time. When you select a tool, say: Zoom In, the previously selected tool will be deactivated. Even if you have more than one tool, only one can be active.

The active tool can be determined by IApplication.CurrentTool
0 Kudos
SebastianKrings
Frequent Contributor
aaah the puzzle is fitting

and currentTool is always set when i click on a tool-button because the method on activate is called and onactivate is the equivalent to onclick of buttons, isnt it?

i think that was what i meant in my second post
or just after clicking the tool's button?


if that's all correct i think it shall work now

thank you very much
0 Kudos