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.

  • Is the OnMouseUp event is called when you close the dialog and then click on the map? – Goldorak84 Aug 27 '14 at 14:30
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.

  • 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 – vinayan Aug 22 '14 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... – SeaJunk Aug 22 '14 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.

  • 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 – vinayan Aug 22 '14 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.