logo资料库

在TOCControl控件中可以调整各个图层的顺序.doc

第1页 / 共2页
第2页 / 共2页
资料共2页,全文预览结束
1、定义全局变量 //调整TOCControl图层的显示顺序 private ITOCControl mTOCControl; private ILayer pMovelayer;//需调整显示顺序的图层 int toIndex;//存放目标图层的索引 2、在窗体 Form1_Load 事件中对 mTOCControl 进行实例化 //调整TOCControl图层的显示顺序 mTOCControl = axTOCControl1.Object as ITOCControl; 3、在 TOCControl 的 OnMouseDown 事件里添加如下代码: //调整TOCControl图层的显示顺序 esriTOCControlItem item1 = esriTOCControlItem.esriTOCControlItemNone; if (e.button == 1) index1); { } IBasicMap map1= null; ILayer layer1 = null; object other1 = null; object index1 = null; mTOCControl.HitTest(e.x, e.y, ref item1, ref map1, ref layer1, ref other1, ref if (item1 == esriTOCControlItem.esriTOCControlItemLayer) { } if (layer1 is IAnnotationSublayer) return; else { } pMovelayer = layer1; 4、在 TOCControl 的 OnMouseUp 事件里添加如下代码: //调整TOCControl图层的显示顺序 private void axTOCControl1_OnMouseUp(object sender, ITOCControlEvents_OnMouseUpEvent e) { if (e.button == 1) { esriTOCControlItem item1 = esriTOCControlItem.esriTOCControlItemNone; IBasicMap map1 = null; ILayer layer1 = null; object other1 = null; object index1 = null; mTOCControl.HitTest(e.x, e.y, ref item1, ref map1, ref layer1, ref other1, ref index1); IMap pMap = axMapControl1.ActiveView.FocusMap;
if (item1 == esriTOCControlItem.esriTOCControlItemLayer || layer1 != null) { if (pMovelayer != layer1) { } ILayer pTempLayer; for (int i = 0; i < pMap.LayerCount; i++) { } pTempLayer = pMap.get_Layer(i); if (pTempLayer == layer1) { } toIndex = i;//获取鼠标点击位置的图层索引号 pMap.MoveLayer(pMovelayer, toIndex);//移动原图层到目标图层位置 axMapControl1.ActiveView.Refresh(); mTOCControl.Update(); } } } 5、运行
分享到:
收藏