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); } } }
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); }
private void tvwLayer_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { if (e.Button == MouseButtons.Right) { //Set item for context menu commands to work with m_contextItem = e.Node.Tag; //Show context menu UID menuID = new UIDClass(); if (e.Node.Tag is IMap) //data frame { menuID.Value = "{F42891B5-2C92-11D2-AE07-080009EC732A}"; //Data Frame Context Menu (TOC) } else //Layer - custom menu { menuID.Value = "{30cb4a78-6eba-4f60-b52e-38bc02bacc89}"; } ICommandBar cmdBar = (ICommandBar)m_application.Document.CommandBars.Find(menuID, false, false); cmdBar.Popup(0, 0); } }