AE 学习小结---toccontrol图层移动

一、关于toccontrol的一些操作

toccontrol图层拖动: 最开始想实现图层拖动时不知道toccontrol属性里可以设置,于是就用代码来实现了,虽然能拖动,但是没有自带的那么美观:

定义全局变量:

private esriTOCControlItem toccItem = esriTOCControlItem.esriTOCControlItemNone;
        private IBasicMap pBasicMap = null;
        private ILayer p_Layer = null;
        //移动图层
        ILayer pMoveLayer;
        ILayer ToLayer;
        int ToIndex;

axTOCControl1_OnMouseDown事件中获得要移动的图层

System.Object unk = null;
System.Object data = null;  

if (e.button == 1)
            {
                axTOCControl1.HitTest(e.x, e.y, ref toccItem, ref pBasicMap, ref p_Layer, ref unk, ref data);
                if (toccItem == esriTOCControlItem.esriTOCControlItemLayer)
                {
                    pMoveLayer = p_Layer ;

               }

            }

axTOCControl1_OnMouseUp事件中获得要移动到的图层位置并使用MoveLayer方法移动图层:

System.Object unk = null;
            System.Object data = null;

            if (e.button == 1)
            {
                axTOCControl1.HitTest(e.x, e.y, ref toccItem, ref pBasicMap, ref p_Layer, ref unk, ref data);

                if (toccItem == esriTOCControlItem.esriTOCControlItemLayer)
                {
                    ToLayer = p_Layer;
                }
                for (i = 0; i < axTOCControl1.ActiveView.FocusMap.LayerCount; i++)
                {
                    if (ToLayer == axTOCControl1.ActiveView.FocusMap.get_Layer(i))
                    {
                        ToIndex = i;
                        break;
                    }
                }
            }
            axTOCControl1.ActiveView.FocusMap.MoveLayer(pMoveLayer, ToIndex);
            axTOCControl1.Update();

在移动时还可以在OnMouseMove事件中定义鼠标样式之类的

其实最简单的还是在toccontrol属性中勾选enable layer drag and drop就能想arcmap中那样拖动图层了!


  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值