private void lstPendingMessage_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right && lstPendingMessage.ContextMenuStrip == null)
            {
                //Before showing the context menu, set ContextItem to be the actual dockable window
                //which represents this definition class in the framework
                IDocument doc = m_application.Document;
                IDockableWindowManager windowManager = m_application as IDockableWindowManager;
                UID dockwinID = new UIDClass();
                dockwinID.Value = this.GetType().GUID.ToString("B");
                IDockableWindow frameworkWindow = windowManager.GetDockableWindow(dockwinID);
                if (doc is IBasicDocument) //ArcMap, ArcScene and ArcGlobe
                {
                    ((IBasicDocument)doc).ContextItem = frameworkWindow;
                }

                //Get the context menu to show
                ICommandBars documentBars = m_application.Document.CommandBars;
                ICommandBar  ctxMenu      = null;
                if (radDynamic.Checked) //Create context menu dynamically
                {
                    //Disadvantage(s):
                    //1. ICommandBars.Create will set document to dirty
                    //2. Cannot insert separator
                    ctxMenu = documentBars.Create("DockableWindowCtxTemp", esriCmdBarType.esriCmdBarTypeShortcutMenu); //This sets document flag to dirty :(

                    //Add commands to context menu
                    UID    cmdID = new UIDClass();
                    object idx   = Type.Missing;

                    cmdID.Value = "{b5820a63-e3d4-42a1-91c5-d90eacc3985b}"; //ClearLoggingCommand
                    ctxMenu.Add(cmdID, ref idx);

                    cmdID.Value = "{21532172-bc21-43eb-a2ad-bb6c333eff5e}"; //LogLineMultiItemCmd
                    ctxMenu.Add(cmdID, ref idx);
                }
                else    //Use predefined context menu
                {
                    UID menuID = new UIDClass();
                    menuID.Value = "{c6238198-5a2a-4fe8-bff0-e2f574f6a6cf}"; //LoggingWindowCtxMnu
                    ICommandItem locateMenu = documentBars.Find(menuID, false, false);
                    if (locateMenu != null)
                    {
                        ctxMenu = locateMenu as ICommandBar;
                    }
                }

                //Pop up context menu at screen location
                Point scrnPoint = lstPendingMessage.PointToScreen(e.Location);
                if (ctxMenu != null)
                {
                    ctxMenu.Popup(scrnPoint.X, scrnPoint.Y);
                }
            }
        }
Exemplo n.º 2
0
        private void CreateContextMenu(IApplication application)
        {
            ICommandBars commandBars = application.Document.CommandBars;
            ICommandBar  commandBar  = commandBars.Create("TemporaryContextMenu", ESRI.ArcGIS.SystemUI.esriCmdBarType.esriCmdBarTypeShortcutMenu);

            System.Object optionalIndex = System.Type.Missing;
            UID           uid           = new UIDClass();

            uid.Value   = ThisAddIn.IDs.AddBookMark.ToString(); //"esriArcMapUI.ZoomInFixedCommand"; // Can use CLSID or ProgID
            uid.SubType = 0;
            commandBar.Add(uid, ref optionalIndex);


            //Show the context menu at the current mouse location
            System.Drawing.Point currentLocation = System.Windows.Forms.Form.MousePosition;
            commandBar.Popup(currentLocation.X, currentLocation.Y);
        }