Visio Drawing Control Context Menu Suppression

Started by Tosh, September 25, 2008, 07:02:23 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Tosh

I've spent days trying to suppress the context menu that the Visio Drawing Control pops up when you right-click on a shape.  I've iterated through the BuiltInMenus, menuSets, and MenuItems and deleted them all, but the context menu still appears.  I've also tried deleting all the AccelItems (not sure what they are, but tried anyway) and that didn't help.

I handled the mouse-up event from the drawing control and set e.cancelDefault = true.  No more context menu, but I also can't use the pointer tool to select shapes or edit the text, so this isn't a viable solution.

There are two context menus in particular I'm trying to suppress.  One comes
from the right-click on the drawing surface (the page?), with no shapes
selected.  It has the following options:
  Cut
  Copy Drawing
  Paste
  ----
  Format >
  Data >
  ----
  Help

The other is comes from the right-click of a shape such as a rectangle,
text, or an image.  These are all displaying the same context menu:
  Cut
  Copy
  Paste
  ----
  Format >
  Data >
  Shape >
  ----
  Help


What am I missing?

Visio Guy

#1
Hey Tosh,

I think that in your MouseUp event, there's a way to determine which button was pushed. Probably hangs off of e.

So only do your menu if the right mouse button is pushed, Otherwise bail from the event proc.
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

Tosh

#2
Visio Guy,

You are right on target with e.button.  Since I'm trying to suppress the built-in menu, I set the e.cancelDefault when the right-button is clicked, and let things roll normally in all other cases.  I could plug in a custom menu after setting e.cancelDefault, but right now I don't need to do that.  The default event handler is crucial for allowing shape selection and entering the text edit mode.

Here's the code that I need:  far simpler than working with BuiltInMenus and other things I'd tried.

        private void drawingControl_MouseUpEvent(object sender, AxMicrosoft.Office.Interop.VisOcx.EVisOcx_MouseUpEvent e)
        {
            if (e.button == (int)VisKeyButtonFlags.visMouseRight)
            {
                e.cancelDefault = true;
            }
        }

Putting this together made my day!  :)