4

In ArcMap, I have a tool that inherits BaseCommand. The tool enables the user to draw a graphic on the screen.

I activated this tool (set as current tool) from a Windows UserForm by getting its reference using ICommandBars.find method.

Now how can the windows form get a notification when the ITool.OnMouseUp method is complete? I see that there are no events generated by the ITool interface.

Sorin Călinică
5,1581 gold badge18 silver badges23 bronze badges
asked Aug 21, 2014 at 11:15
1
  • Is the OnMouseUp event is called when you close the dialog and then click on the map? Commented Aug 27, 2014 at 14:30

3 Answers 3

2

For a tool, you should be inheriting from BaseTool. If you have developed the tool as a COM object, rather than an add-in, you can pass a reference from the form to the tool via a property or variable on the tool. In the tools OnMouseUp event you can then do what you want to the form through the reference.

answered Aug 21, 2014 at 18:48
2
  • I am inheriting BaseTool..it is not an add-in..Could you elaborate how I can set a property or variable on the tool from outside? It looked impossible to do for me or I am missing something big Commented Aug 22, 2014 at 1:16
  • 2
    I think this approach can only be done in c++. On your tool class you expose a public property or variable. From your form you can find the tool as an ICommandItem and from there get at the underlying class via ICommandItem.Command, then set the public property. The weird thing is I cant see ICommandItem.Command in any of the .net languages... Commented Aug 22, 2014 at 5:03
1

My first idea was to override your tools OnMouseUp() method and fire an event that you listen for in your form but that might not work (never tried this)

The safer way might be to use a windows hook. These are low-level mechanisms to intercept events. You can read more on the windows help page "Hooks Overview". I'd use WH_MOUSE_LL in your case.

answered Aug 21, 2014 at 13:37
1
  • i tried firing an event..but unable to subscribe to it because that event is not part of the ITool interface..casting an ITool to the classname of the tool throws exception Commented Aug 22, 2014 at 1:18
1

The OnMouseUp event is only fired when you click somehere on the map. If you click on your dialog, or anywhere outside the map, the event won't fire.

If you're clicking on the map, and try to fire an event on a (non modal) dialog, then you can follow SeaJunk's idea.

  • On your tool, Implement an interface with a function that allows you to pass a reference to your form, then, on your onMouseUp event, y can call some function to your form

    interface IFormNotifier
    {
     void SetFormToBeNotified(Form form);
    }
    class YourTool : BaseTool , IFormNotifier
    {
     Form _formToBeNotified = null;
     ... your code ...
     //IFormNotifier implementation
     void SetFormToBeNotified(Form form)
     {
     _formToBeNotified = form;
     }
     //OnMouseUp Event
     public void OnMouseUp (
     int button,
     int shift,
     int x,
     int y)
     {
     //Call a function on your form
     if(_formToBeNotified != null)
     _formToBeNotified.callwhatheverfunctiontonotify();
     }
    }
    

To access the IFormNotifier from the ICommandItem you found with the ICommandBars.find method, you should cast the ICommandItem.Command property as an IFormNotifier.

ICommandItem itemFound = commandBar.find(....);
if(itemFound != null)
{
 IFormNotifier formNotifier = itemFound.Command as IFormNotifier;
 //set the form
 if(formNotifier != null)
 formNotifier.SetFormToBeNotified(this);
}

That way, your non modal dialog will get notifications the next time you click on the map. It's important that when you close your dialog, set the form to be notified to null, to avoid accessing a deleted form.

answered Aug 27, 2014 at 15:08

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.