private IToolbarMenu m_menuMap = null;//全局变量
private IMapControl3 m_mapControl = null;
主窗体Load事件中加入:
m_mapControl = (IMapControl3)this.axMapControl1.Object;
m_menuMap = new ToolbarMenuClass();
//ICommand命令
m_menuMap.AddItem( new ControlsMapFullExtentCommand(), -1, 0, false, esriCommandStyles.esriCommandStyleIconAndText);
m_menuMap.AddItem(new ControlsMapPanTool(), -1, 1, false, esriCommandStyles.esriCommandStyleIconAndText);
m_menuMap.AddItem(new ControlsMapZoomInTool(), -1, 2, false, esriCommandStyles.esriCommandStyleIconAndText);
m_menuMap.AddItem(new ControlsMapZoomOutTool(), -1, 3, false, esriCommandStyles.esriCommandStyleIconAndText);
m_menuMap.AddItem(new ControlsAddDataCommandClass(), -1, 4, false, esriCommandStyles.esriCommandStyleIconAndText);
m_menuMap.SetHook(m_mapControl);//很重要
private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
{
if (e.button == 2)
{
//弹出右键菜单
m_menuMap.PopupMenu(e.x, e.y, m_mapControl.hWnd);
}
}