今天用ArcEngine 中的组件堆成一个小窗体,想添加一些右键功能。如何实现删除鼠标左键已经选中的选项。请高手们给点代码例子! 谢谢

解决方案 »

  1.   

    可以用ContextMenu,添加你想要的菜单,实现功能,然后关联datagridview和ContextMenu即可
      

  2.   

    contextmenu控件已经做出来了,不过做的是在鼠标位置处显示右键菜单,怎么做到给选中项(是我在小程序中打开的一个文件,随即的)添加固定的右键功能? 请大侠们给点帮助
      

  3.   

    右击toccontrol 产生removelayer
    removelayer.cs
      public sealed class RemoveLayer : BaseCommand
        {
            private IMapControl3 m_mapControl;        public RemoveLayer()
            {
                base.m_caption  = " Remove Layer";
            }        public override void OnClick()
            {
                ILayer pLayer = (ILayer)m_mapControl.CustomProperty;
                m_mapControl.Map.DeleteLayer(pLayer);
            }        public override void OnCreate(object hook)
            {
                m_mapControl = (IMapControl3)hook;
            }
        }
    load事件中:
    m_menuLayer = new ToolbarMenuClass();
                m_menuLayer.AddItem(new  RemoveLayer(), -1, 0, false, esriCommandStyles.esriCommandStyleTextOnly);
    toccontrol_onmousedown事件中:
      //右击删除图层
                    esriTOCControlItem item = esriTOCControlItem.esriTOCControlItemNone;
                    IBasicMap map = null; ILayer layer = null;
                    object other = null; object index = null;
       m_tocControl.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index);
     //Ensure the item gets selected 
                    if (item == esriTOCControlItem.esriTOCControlItemMap)
                        m_tocControl.SelectItem(map, null);
                    //axTOCControl1.SelectItem(map, null);
                    else
                        m_tocControl.SelectItem(layer, null);
                    //axTOCControl1.SelectItem(layer, null);                //Set the layer into the CustomProperty (this is used by the custom layer commands)
                    m_mapControl.CustomProperty = layer;
                    //axTOCControl1.CustomProperty = layer;                //Popup the correct context menu
                    if (item == esriTOCControlItem.esriTOCControlItemMap) m_menuMap.PopupMenu(e.x, e.y, axTOCControl1.hWnd);
                    if (item == esriTOCControlItem.esriTOCControlItemLayer) m_menuLayer.PopupMenu(e.x, e.y, axTOCControl1.hWnd);