I have a created a custom context menu using ICommandBar and am displaying it on create feature mouse-down right click. I am constructing a point collection on each mouse down and then creating a polyline. For each point I am refreshing using EditSketch.RefreshSketch().

On right click, I created a custom context menu to finish the sketch. Sometimes, I get the default "Sketch Tool/Select Elements" context menu, which I do not want to get on right click.

The code that I'm using to display the context menu:

public override void OnMouseDown(int Button, int Shift, int X, int Y)
  if (Button == 2)
    _objContextMenu.Popup(0, 0);
  • Which version of ArcGIS Desktop are you developing for? – blah238 Nov 26 '12 at 5:29
  • arcGis Desktop 9.3.1 – user13085 Nov 26 '12 at 5:50

You need to 'short circuit' the OnContextMenu and tell ArcGIS that everything's sorted.

public override bool OnContextMenu(int X, int Y)

      return true; // or allow some condition where the context menu is allowed
| improve this answer | |
  • My apologies for the one line answer, I was in a hurry when I wrote it. In order to dismiss the existing context menu one must override the OnContextMenu then you can use the OnMouseDown (if Button == 2) for a right click. The coordinates given for the OnMouseDown are in screen coordinates from the application (ArcMap) window, once you know ArcMap's location add it to the X and Y to set the form properties me.Left and me.Top (I think that's VB but C# has something similar). – Michael Stimson Feb 12 '13 at 23:29
  • The IWindowPosition object will give you the location of the ArcMap frame, this post discusses the windows location of the screen display link – Michael Stimson Feb 12 '13 at 23:52

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.