<?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 Re: How to add handler to mouse click on the map of ArcMap? in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-add-handler-to-mouse-click-on-the-map-of/m-p/119973#M3125</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Sui-&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I don't think you want to get a reference to your IMapControl2 object using the new keyword. I think you need to query interface from an existing object.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Something like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
IMapControl4 mapControl = axMapControl1.Object as IMapControl4;
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Do you have an axMapControl1 object somewhere?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 06:59:24 GMT</pubDate>
    <dc:creator>RichWawrzonek</dc:creator>
    <dc:date>2021-12-11T06:59:24Z</dc:date>
    <item>
      <title>How to add handler to mouse click on the map of ArcMap?</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-add-handler-to-mouse-click-on-the-map-of/m-p/119970#M3122</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Everybody:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; I am writing an ArcMap 10 extension using C#. I want to detect the user's mouse click on the map. However, I haven't successfully get it done.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; I notice that IMapControlEvent2 should give a delegate to handle the event, but I don't know how to get IMapControlEvent2 out of the current application. I did the following but it doesn't work:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;***************************************************************&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;IActiveView view = (_mApplication.Document as IMxDocument).ActivatedView; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;IMapControlDefault mapControlDefault = new MapControl(); &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mapControlDefault.Map = view.FocusMap; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;IMapControlEvents2 mapControlEvents = mapControlDefault as IMapControlEvents2; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;***************************************************************&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; How shall I do it?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Thank you!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Jun 2012 21:07:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-add-handler-to-mouse-click-on-the-map-of/m-p/119970#M3122</guid>
      <dc:creator>SuiHuang</dc:creator>
      <dc:date>2012-06-14T21:07:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to add handler to mouse click on the map of ArcMap?</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-add-handler-to-mouse-click-on-the-map-of/m-p/119971#M3123</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Everybody:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Just an update that the event interface object is retrieved, but the application still does not respond. Here is my code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;*************************************************************************&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;IMapControlDefault mapControlDefault = new MapControl();&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mapControlDefault.Map = view.FocusMap;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mapControlDefault.FlashShape(_CurrentFeatureBo.ShapeCopy);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;IMapControlEvents2_Event mapControlEvents = mapControlDefault as IMapControlEvents2_Event;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mapControlEvents.OnMouseDown += new IMapControlEvents2_OnMouseDownEventHandler(mapControlEvents_OnMouseDown);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mapControlEvents.OnViewRefreshed += new IMapControlEvents2_OnViewRefreshedEventHandler(mapControlEvents_OnViewRefreshed);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;void mapControlEvents_OnViewRefreshed(object ActiveView, int viewDrawPhase, object layerOrElement, object envelope)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MessageBox.Show("refreshed");&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;void mapControlEvents_OnMouseDown(int button, int shift, int X, int Y, double mapX, double mapY)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MessageBox.Show("clicked");&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;*************************************************************************&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When I click on the map or refresh the map in ArcMap. The message boxes in event handlers do not show up.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;How shall I change it?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hi Everybody:&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; I am writing an ArcMap 10 extension using C#. I want to detect the user's mouse click on the map. However, I haven't successfully get it done.&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; I notice that IMapControlEvent2 should give a delegate to handle the event, but I don't know how to get IMapControlEvent2 out of the current application. I did the following but it doesn't work:&lt;BR /&gt;***************************************************************&lt;BR /&gt;IActiveView view = (_mApplication.Document as IMxDocument).ActivatedView; &lt;BR /&gt;IMapControlDefault mapControlDefault = new MapControl(); &lt;BR /&gt;mapControlDefault.Map = view.FocusMap; &lt;BR /&gt;IMapControlEvents2 mapControlEvents = mapControlDefault as IMapControlEvents2; &lt;BR /&gt;***************************************************************&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; How shall I do it?&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Thank you!&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Jun 2012 21:46:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-add-handler-to-mouse-click-on-the-map-of/m-p/119971#M3123</guid>
      <dc:creator>SuiHuang</dc:creator>
      <dc:date>2012-06-14T21:46:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to add handler to mouse click on the map of ArcMap?</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-add-handler-to-mouse-click-on-the-map-of/m-p/119972#M3124</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Everybody:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; More update...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; I tried the following code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
// variable declarations in class level
private IMapControlEvents2_Event mapControlEvents = null;
private IMapControlDefault mapControlDefault = null;

// wiring up the events in one of the called member function, each event handler use MessageBox.Show to display a message
mapControlDefault = new MapControl();
mapControlDefault.Map = view.FocusMap;
mapControlEvents = mapControlDefault as IMapControlEvents2_Event;
mapControlEvents.OnMouseDown += new IMapControlEvents2_OnMouseDownEventHandler(mapControlEvents_OnMouseDown);
mapControlEvents.OnSelectionChanged += new IMapControlEvents2_OnSelectionChangedEventHandler(mapControlEvents_OnSelectionChanged);
mapControlEvents.OnMouseUp += new IMapControlEvents2_OnMouseUpEventHandler(mapControlEvents_OnMouseUp);
mapControlEvents.OnMouseMove += new IMapControlEvents2_OnMouseMoveEventHandler(mapControlEvents_OnMouseMove);
mapControlEvents.OnDoubleClick += new IMapControlEvents2_OnDoubleClickEventHandler(mapControlEvents_OnDoubleClick);
mapControlEvents.OnExtentUpdated += new IMapControlEvents2_OnExtentUpdatedEventHandler(mapControlEvents_OnExtentUpdated);
mapControlEvents.OnKeyDown += new IMapControlEvents2_OnKeyDownEventHandler(mapControlEvents_OnKeyDown);
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;By experiment I found that in these events only OnExtentUpdated and OnSelectionChanged response. All the events related to mouse and key press are not responding. Anybody know why?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:59:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-add-handler-to-mouse-click-on-the-map-of/m-p/119972#M3124</guid>
      <dc:creator>SuiHuang</dc:creator>
      <dc:date>2021-12-11T06:59:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to add handler to mouse click on the map of ArcMap?</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-add-handler-to-mouse-click-on-the-map-of/m-p/119973#M3125</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Sui-&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I don't think you want to get a reference to your IMapControl2 object using the new keyword. I think you need to query interface from an existing object.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Something like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
IMapControl4 mapControl = axMapControl1.Object as IMapControl4;
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Do you have an axMapControl1 object somewhere?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:59:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-add-handler-to-mouse-click-on-the-map-of/m-p/119973#M3125</guid>
      <dc:creator>RichWawrzonek</dc:creator>
      <dc:date>2021-12-11T06:59:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to add handler to mouse click on the map of ArcMap?</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-add-handler-to-mouse-click-on-the-map-of/m-p/119974#M3126</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi richwawr:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Do you mean I need to have an ESRI.ArcGIS.Controls.AxMapControl object? I found this class by Visual Studio intellisense, but I was not able to find how to get this object, neither find the help document of this class.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Further hinds?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Thank you.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sui&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Sui-&lt;BR /&gt;I don't think you want to get a reference to your IMapControl2 object using the new keyword. I think you need to query interface from an existing object.&lt;BR /&gt;&lt;BR /&gt;Something like this:&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
IMapControl4 mapControl = axMapControl1.Object as IMapControl4;
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;Do you have an axMapControl1 object somewhere?&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:59:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-add-handler-to-mouse-click-on-the-map-of/m-p/119974#M3126</guid>
      <dc:creator>SuiHuang</dc:creator>
      <dc:date>2021-12-11T06:59:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to add handler to mouse click on the map of ArcMap?</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-add-handler-to-mouse-click-on-the-map-of/m-p/119975#M3127</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Are you using ArcEngine?&amp;nbsp; I assumed you were since you were trying to use the IMapControl. That interface is for accessing the map of an ArcEngine control.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Jun 2012 19:01:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-add-handler-to-mouse-click-on-the-map-of/m-p/119975#M3127</guid>
      <dc:creator>RichWawrzonek</dc:creator>
      <dc:date>2012-06-19T19:01:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to add handler to mouse click on the map of ArcMap?</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-add-handler-to-mouse-click-on-the-map-of/m-p/119976#M3128</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi richwawr:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; I don't think I am using ArcEngine, and I am not suppose to, because I am just developing an ArcMap extension, not a stand alone application.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Should I use IMapControl only if I have ArcEngine license? Then how shall I capture the mouse-click event on ArcMap?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Thank you!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Are you using ArcEngine?&amp;nbsp; I assumed you were since you were trying to use the IMapControl. That interface is for accessing the map of an ArcEngine control.&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Jun 2012 20:16:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-add-handler-to-mouse-click-on-the-map-of/m-p/119976#M3128</guid>
      <dc:creator>SuiHuang</dc:creator>
      <dc:date>2012-06-19T20:16:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to add handler to mouse click on the map of ArcMap?</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-add-handler-to-mouse-click-on-the-map-of/m-p/119977#M3129</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;That really depends on what you are trying to do. Are you trying to return information from a feature clicked in the map? Trying to pop up a context menu when user right-clicks? It's all different. Please define what you are trying to acheive.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;A typical scenario is the need to capture the location when a user left-click the map. To accomplish this I create a ITool that the user activates prior to clicking. The ITool provides event handlers such as OnMouseUp that you can add code to.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Jun 2012 21:01:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-add-handler-to-mouse-click-on-the-map-of/m-p/119977#M3129</guid>
      <dc:creator>RichWawrzonek</dc:creator>
      <dc:date>2012-06-19T21:01:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to add handler to mouse click on the map of ArcMap?</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-add-handler-to-mouse-click-on-the-map-of/m-p/119978#M3130</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you richwawr! I am trying the ITool approach.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;That really depends on what you are trying to do. Are you trying to return information from a feature clicked in the map? Trying to pop up a context menu when user right-clicks? It's all different. Please define what you are trying to acheive.&lt;BR /&gt;&lt;BR /&gt;A typical scenario is the need to capture the location when a user left-click the map. To accomplish this I create a ITool that the user activates prior to clicking. The ITool provides event handlers such as OnMouseUp that you can add code to.&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Jun 2012 22:00:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-add-handler-to-mouse-click-on-the-map-of/m-p/119978#M3130</guid>
      <dc:creator>SuiHuang</dc:creator>
      <dc:date>2012-06-19T22:00:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to add handler to mouse click on the map of ArcMap?</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-add-handler-to-mouse-click-on-the-map-of/m-p/119979#M3131</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi! richwawr:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Instead of directly using ITool, I directly inherit BaseTool and register it to ArcMap (following the style of making a custom tool). Because the tool's activation needs to deactivate the other tools in ArcMap, I think registering it to ArcMap is necessary. Am I right? Or there is simpler way to detect the mouse click?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Following is my code for now. Thank you!&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
// set the tool with hardcoded UID to current
ICommandBars documentBars = _mApplication.Document.CommandBars;
UID cmdID = new UIDClass();
cmdID.Value = "{0dxxc599-c213-4xxb-8978-1227bac1bx8d}";
ICommandItem cmdItem = documentBars.Find(cmdID, false, false);
(cmdItem.Command as TestTool).rollbackTool = _mApplication.CurrentTool;
_mApplication.CurrentTool = cmdItem;


[Guid("0dxxc599-c213-4xxb-8978-1227bac1bx8d")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("CustTool.TestTool")]
public class TestTool : BaseTool
{
&amp;nbsp;&amp;nbsp;&amp;nbsp; // registration methods
&amp;nbsp;&amp;nbsp;&amp;nbsp; // ...
&amp;nbsp;&amp;nbsp;&amp;nbsp; // OnCreate method
&amp;nbsp;&amp;nbsp;&amp;nbsp; // ..

&amp;nbsp;&amp;nbsp;&amp;nbsp; public ICommandItem rollbackTool = null;
&amp;nbsp;&amp;nbsp;&amp;nbsp; private IApplication mApplication = null;
&amp;nbsp;&amp;nbsp;&amp;nbsp; public override void OnMouseDown(int button, int shift, int x, int y)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // do the work
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mApplication.CurrentTool = this.rollbackTool;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
}
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;That really depends on what you are trying to do. Are you trying to return information from a feature clicked in the map? Trying to pop up a context menu when user right-clicks? It's all different. Please define what you are trying to acheive.&lt;BR /&gt;&lt;BR /&gt;A typical scenario is the need to capture the location when a user left-click the map. To accomplish this I create a ITool that the user activates prior to clicking. The ITool provides event handlers such as OnMouseUp that you can add code to.&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:59:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-add-handler-to-mouse-click-on-the-map-of/m-p/119979#M3131</guid>
      <dc:creator>SuiHuang</dc:creator>
      <dc:date>2021-12-11T06:59:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to add handler to mouse click on the map of ArcMap?</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-add-handler-to-mouse-click-on-the-map-of/m-p/119980#M3132</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Are you using Visual Studio? There are templates in VS to create custom tools for ArcMap. You can create them as COM extensions (need an installer to deploy) or using the newer Add-in framework. I recommend the Add-in method because it makes deployment much easier. It looks like your code is attempting to use the COM method. There is a lot more to it than what you have and yes it has to be registered. Do you have the template?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Jun 2012 18:00:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-add-handler-to-mouse-click-on-the-map-of/m-p/119980#M3132</guid>
      <dc:creator>RichWawrzonek</dc:creator>
      <dc:date>2012-06-20T18:00:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to add handler to mouse click on the map of ArcMap?</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-add-handler-to-mouse-click-on-the-map-of/m-p/119981#M3133</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi richwawr:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Yes I am using Visual Studio, and I actually created the code with template and then modified it. I am using the COM approach because COM can still do more then Add-in, even though Add-in is easy to deploy.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; The reason I why I was not using the custom tool template at the beginning is that: I don't actually want to create a tool with a button on the ArcMap toolbar. Instead I want to make a button on a windows form to bring user into a state of picking features on the map, so I tried to handle the map events first. However, I still end up building a tool (but hide it from the toolbar) &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; I just use the following derived BaseTool classes to allow the state of ArcMap tool rollback to original after user has interacted.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Any better idea?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Thank you!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public abstract class RollbackableToolBase : BaseTool&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; { &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; protected IApplication m_Application = null;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public ICommandItem RollbackTool { get; set; }&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public override sealed void OnCreate(object hook) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_Application = hook as IApplication; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; public class RollbackableTool1 : RollbackableToolBase&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; { &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public RollbackableTool1 () &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Result = null; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // the shoot event &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public event RanEventHandler Ran= null;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public object Result { get; private set; }&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public override void OnMouseDown(int button, int shift, int x, int y) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // interact with the screen and get the result&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // restore the current tool &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_Application.CurrentTool = this.RollbackTool; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; public delegate void RanEventHandler(object sender, EventArgs e);&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Are you using Visual Studio? There are templates in VS to create custom tools for ArcMap. You can create them as COM extensions (need an installer to deploy) or using the newer Add-in framework. I recommend the Add-in method because it makes deployment much easier. It looks like your code is attempting to use the COM method. There is a lot more to it than what you have and yes it has to be registered. Do you have the template?&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Jun 2012 14:34:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-add-handler-to-mouse-click-on-the-map-of/m-p/119981#M3133</guid>
      <dc:creator>SuiHuang</dc:creator>
      <dc:date>2012-06-21T14:34:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to add handler to mouse click on the map of ArcMap?</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-add-handler-to-mouse-click-on-the-map-of/m-p/119982#M3134</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;So is it working ok now? You seem to be doing it right. Use the template to build the ITool, then hide it from the toolbar. Because it is a COM tool you can access it by the GUID. It doesn't need to be re-registered at runtime. It gets registered when it is installed. Then it is available to you when ArcMap starts via the GUID.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Jun 2012 17:45:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-add-handler-to-mouse-click-on-the-map-of/m-p/119982#M3134</guid>
      <dc:creator>RichWawrzonek</dc:creator>
      <dc:date>2012-06-21T17:45:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to add handler to mouse click on the map of ArcMap?</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-add-handler-to-mouse-click-on-the-map-of/m-p/119983#M3135</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi richwawr:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Yes it is working for me now. Thank you for your help!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sui&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;So is it working ok now? You seem to be doing it right. Use the template to build the ITool, then hide it from the toolbar. Because it is a COM tool you can access it by the GUID. It doesn't need to be re-registered at runtime. It gets registered when it is installed. Then it is available to you when ArcMap starts via the GUID.&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Jun 2012 19:45:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-add-handler-to-mouse-click-on-the-map-of/m-p/119983#M3135</guid>
      <dc:creator>SuiHuang</dc:creator>
      <dc:date>2012-06-21T19:45:07Z</dc:date>
    </item>
  </channel>
</rss>

