一、关于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中那样拖动图层了!