TOCControl右键菜单
来源:互联网 发布:mac chrome加载flash 编辑:程序博客网 时间:2024/06/05 06:27
两种方式:(一种是原模式,一种是装饰模式)
1、原模式
private ITOCControl2 m_tocControl;
private IMapControl3 m_mapControl;
private IToolbarMenu m_menuMap;
private IToolbarMenu m_menuLayer;
m_tocControl = (ITOCControl2)axTOCControl1.Object;
m_mapControl = (IMapControl3)axMapControl1.Object;
//Add custom commands to the map menu
m_menuMap = new ToolbarMenuClass();
m_menuMap.AddItem(new LayerVisibility(), 1, 0, false, esriCommandStyles.esriCommandStyleTextOnly);//添加
m_menuMap.AddItem(new LayerVisibility(), 2, 1, false, esriCommandStyles.esriCommandStyleTextOnly);
//Add pre-defined menu to the map menu as a sub menu
m_menuMap.AddSubMenu("esriControls.ControlsFeatureSelectionMenu", 2, true);
//Add custom commands to the map menu
m_menuLayer = new ToolbarMenuClass();
m_menuLayer.AddItem(new RemoveLayer(), -1, 0, false, esriCommandStyles.esriCommandStyleTextOnly);
m_menuLayer.AddItem(new ScaleThresholds(), 1, 1, true, esriCommandStyles.esriCommandStyleTextOnly);
m_menuLayer.AddItem(new ScaleThresholds(), 2, 2, false, esriCommandStyles.esriCommandStyleTextOnly);
m_menuLayer.AddItem(new ScaleThresholds(), 3, 3, false, esriCommandStyles.esriCommandStyleTextOnly);
m_menuLayer.AddItem(new LayerSelectable(), 1, 4, true, esriCommandStyles.esriCommandStyleTextOnly);
m_menuLayer.AddItem(new LayerSelectable(), 2, 5, false, esriCommandStyles.esriCommandStyleTextOnly);
m_menuLayer.AddItem(new ZoomToLayer(), -1, 6, true, esriCommandStyles.esriCommandStyleTextOnly);
//Set the hook of each menu
m_menuLayer.SetHook(m_mapControl);
m_menuMap.SetHook(m_mapControl);
private void axTOCControl1_OnMouseDown(object sender, ITOCControlEvents_OnMouseDownEvent e)
{
if (e.button != 2) return;
esriTOCControlItem item = esriTOCControlItem.esriTOCControlItemNone;//选择item的类型,有Map,Layer,Legend
IBasicMap map = null; ILayer layer = null;
object other = null; object index = null;
//Determine what kind of item is selected
m_tocControl.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index);
//Ensure the item gets selected
if (item == esriTOCControlItem.esriTOCControlItemMap)
m_tocControl.SelectItem(map, null);//设置SelectItem,通过GetSelectItem获取。
else
m_tocControl.SelectItem(layer, null);
//Set the layer into the CustomProperty (this is used by the custom layer commands)
m_mapControl.CustomProperty = layer;//设置CustomProperty属性,这个属性在ICommand接口的Hook中获取,进行对该Layer操作。
//Popup the correct context menu
if (item == esriTOCControlItem.esriTOCControlItemMap) m_menuMap.PopupMenu(e.x, e.y, m_tocControl.hWnd);
if (item == esriTOCControlItem.esriTOCControlItemLayer) m_menuLayer.PopupMenu(e.x, e.y, m_tocControl.hWnd);
}
2、装饰模式
在项目中添加新项【Arcgis】-【Context Menu(AE)】,用此模板完成。
EngineContextMenu1 menucontext = new EngineContextMenu1();
menucontext.SetHook(axMapControl1.Object);
menucontext.PopupMenu(e.x, e.y, m_tocControl.hWnd);
EngineContextMenu1 类有SetHook(),PopupMenu()和IToolbarMenu2 ContextMenu属性。
- TOCControl右键菜单
- TOCControl右键菜单
- TOCControl右键菜单功能实现
- TOCControl的常见右键操作
- C# ArcEngine TOCControl上实现右键
- C# ArcEngine TOCControl上实现右键
- 右键菜单
- 右键菜单
- 右键菜单
- 右键菜单
- 右键菜单
- 右键菜单
- 右键菜单
- 右键菜单
- 右键菜单
- 右键菜单
- 右键菜单
- 右键菜单
- struts 和servlet的关系
- 哪种类型的充电管理ic市场应用最多
- 第七周项目 3 简单分支问题体验 3
- Socket 通信编程全方位考虑小实例加源码
- 虚析构函数
- TOCControl右键菜单
- IplImage, CvMat, Mat 的关系
- struts2日期类型转换
- 正确配置vnc + haproxy
- 深度优先搜索
- Javascript中关键参数this浅析
- flume学习安装
- java日期转换
- 人力资源管理系统要具备哪些功能?