ArcGIS Engine 中实现右键出现快捷键菜单栏

先看看效果过图

实现是上图的效果主要需要用到axMapControl1_OnMouseDown事件,在点击事件中判断是点击的右键还是左键,进行弹出

直接贴代码:

      private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        {
            #region  主窗体右键
            /////地图视窗鼠标事件
            IToolbarMenu mapPopMenu = null;
            mapPopMenu = new ToolbarMenu();//这个很关键,主要应用SDK封装的工具类似于C#的OpenDialog
            if (e.button == 2)
            {
                /* IMap pMap = axMapControl1.Map;
                 IActiveView pActiveView = pMap as IActiveView;
                 IEnvelope pEnv = axMapControl1.TrackRectangle();
                 pActiveView.Extent = pEnv;
                 pActiveView.Refresh();*/

                //地图视窗右键菜单功能

                mapPopMenu.AddItem(new ControlsSelectTool(), -1, 0, false, esriCommandStyles.esriCommandStyleIconAndText);
                mapPopMenu.AddItem(new ControlsMapPanTool(), -1, 1, false, esriCommandStyles.esriCommandStyleIconAndText);
                mapPopMenu.AddItem(new ControlsMapFullExtentCommand(), -1, 2, false, esriCommandStyles.esriCommandStyleIconAndText);
                mapPopMenu.AddItem(new ControlsMapIdentifyTool(), -1, 3, false, esriCommandStyles.esriCommandStyleIconAndText);//识别工具
                mapPopMenu.AddItem(new ControlsMapZoomInFixedCommand(), -1, 4, false, esriCommandStyles.esriCommandStyleIconAndText);//
                mapPopMenu.AddItem(new ControlsMapZoomInFixedCommand(), -1, 5, false, esriCommandStyles.esriCommandStyleIconAndText);
                mapPopMenu.AddItem(new ControlsSelectFeaturesTool(), -1, 6, false, esriCommandStyles.esriCommandStyleIconAndText);//选择要素工具
                mapPopMenu.AddItem(new ControlsClearSelectionCommand(), -1, 7, false, esriCommandStyles.esriCommandStyleIconAndText);//缩放所选要素
                mapPopMenu.AddItem(new ControlsZoomToSelectedCommand(), -1, 8, false, esriCommandStyles.esriCommandStyleIconAndText);
                mapPopMenu.AddItem(new ControlsMapZoomToLastExtentBackCommand(), -1, 9, false, esriCommandStyles.esriCommandStyleIconAndText);
                mapPopMenu.AddItem(new ControlsMapZoomToLastExtentForwardCommand(), -1, 10, false, esriCommandStyles.esriCommandStyleIconAndText);
                mapPopMenu.SetHook(axMapControl1);//// 得到地图视窗右键菜单
                mapPopMenu.PopupMenu(e.x, e.y, axMapControl1.hWnd);//弹出显示菜单
            }
            /*  if (e.button == 1)//左键因为右键要取消
              {
                  IMap pMap = axMapControl1.Map;
                   IActiveView pActiveView = pMap as IActiveView;
                   IEnvelope pEnv = axMapControl1.TrackRectangle();
                   pActiveView.Extent = pEnv;
                   pActiveView.Refresh();
              }
             * */
            //此事件不会触发
            if (e.button == 3)//如果鼠标中间改为ControlsMapPanTool会更好
            {
                IMap pMap = axMapControl1.Map;
                IActiveView pActiveView = pMap as IActiveView;
                IEnvelope pEnv = axMapControl1.TrackRectangle();
                pActiveView.Extent = pEnv;
                pActiveView.Refresh();
            }
 
        }

猜你喜欢

转载自blog.csdn.net/weixin_40184249/article/details/80464401