AE:控件TOCControl右击

 

 

 

IMapControl2 m_pMapCtrl = axMapControl.Object as IMapControl2;

IMap m_pMap = axMapControl.Map;

ITOCControl m_pTocCtrl = axTOCControl1.Object as ITOCControl;

IToolbarControl m_pToolbarCtrl = axToolbarControl1.Object as IToolbarControl;

 

m_pTocCtrl.SetBuddyControl(axMapControl.Object);//关联MapControl控件

m_pToolbarCtrl.SetBuddyControl(axMapControl.Object);//关联MapControl控件

 

 

private void OnTocCtrlMouseDown(object sender, ITOCControlEvents_OnMouseDownEvent e)

 {

    try

    {

        esriTOCControlItem eTocCtrlItem = esriTOCControlItem.esriTOCControlItemNone;

        IBasicMap pBasicMap = null;

        ILayer pLyrSelect = null;

        object other = null;

        object index = null;

 

        axTOCControl1.HitTest(e.x, e.y, ref eTocCtrlItem, ref pBasicMap, ref pLyrSelect, ref other, ref index);

        if (e.button == 2)

        {   //右键

            if (eTocCtrlItem == esriTOCControlItem.esriTOCControlItemMap)

            {

                axTOCControl1.SelectItem(pBasicMap, null);

            }

            else if (eTocCtrlItem == esriTOCControlItem.esriTOCControlItemLayer)

            {

                axTOCControl1.SelectItem(pLyrSelect, null);

                (m_pMapCtrl as IMapControl3).CustomProperty = pLyrSelect;//保存当前选中的层

            }

 

            if (eTocCtrlItem == esriTOCControlItem.esriTOCControlItemMap)//右击选中根节点

            {

                contextMapMenuStrip.Show(axTOCControl1, e.x, e.y);

            }

 

            if (eTocCtrlItem == esriTOCControlItem.esriTOCControlItemLayer)//右击选中子节点

            {

                contextLayerMenuStrip.Show(axTOCControl1, e.x, e.y);

            }

        }

        else if (e.button == 1)

        {   //左键

            if (eTocCtrlItem == esriTOCControlItem.esriTOCControlItemLegendClass)

            {   //显示图例

                //new ESRI.ArcGIS.Display.Symbol.SymbolSelectionDialog().ShowDialog();

                

            }

            if (eTocCtrlItem == esriTOCControlItem.esriTOCControlItemLayer)   

            {

                axTOCControl1.SelectItem(pLyrSelect, null);

 

                if (pLyrSelect is GroupLayerClass)  //组合图层

                {

                    bool bVisible = pLyrSelect.Visible;

 

                    GroupLayerClass pGroupLayer = pLyrSelect as GroupLayerClass;

 

                    for (int i = 0; i <= pGroupLayer.Count - 1; i++)

                    {

                        pGroupLayer.get_Layer(i).Visible = !bVisible;

 

                    }

 

                }

                else  // 单一的图层

                {

                    if (pBasicMap != null)

                    {

                        ILayer pLyrTmp = null;

                        int iCount = pBasicMap.LayerCount;

                        bool bHasFindGroupLayer = false;

                        for (int index1 = 0; index1 < iCount; index1++)

                        {

                            pLyrTmp = pBasicMap.get_Layer(index1);

                            if (pLyrTmp is GroupLayerClass)

                            {

                                GroupLayerClass pGroupLayer = pLyrTmp as GroupLayerClass;

 

                                for (int i = 0; i <= pGroupLayer.Count - 1; i++)

                                {

                                    if (pGroupLayer.get_Layer(i).Name == pLyrSelect.Name)

                                    {

                                        pGroupLayer.Visible = true;

                                        bHasFindGroupLayer = true;

                                        break;

                                    }

 

                                }

                            }

                            if (bHasFindGroupLayer == true)

                                break;

                        }

                    }

                }

            }

        }

    }

    catch (Exception ee)

    {

        System.Diagnostics.Debug.WriteLine(ee.ToString());

    }

}

 

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值