Home > Net >  Can you help to see what is wrong? TOCControl right-click menu to add, thank you!
Can you help to see what is wrong? TOCControl right-click menu to add, thank you!

Time:10-01

Private IMapControl3 m_mapControl;
Private ITOCControl2 m_pTocControl;
Private IToolbarMenu m_pMenuLayer;
Private void Form1_Load (object sender, EventArgs e)
{
AxTOCControl1. SetBuddyControl (axMapControl1);
M_pMenuLayer=new ToolbarMenuClass ();
M_pMenuLayer. AddItem (new RemoveLayer (), 1, 0, false, esriCommandStyles. EsriCommandStyleTextOnly);
M_pMenuLayer. AddItem (new ZoomToLayer (), 1, 1, true, esriCommandStyles. EsriCommandStyleTextOnly);
M_pMenuLayer. SetHook (m_mapControl);
}


Private void axTOCControl1_OnMouseDown (object sender, ITOCControlEvents_OnMouseDownEvent e)
{
If (e.b utton!=2) {return; }
EsriTOCControlItem pItem=esriTOCControlItem. EsriTOCControlItemNone;
IBasicMap pMap=null;
ILayer pLayer=null;
The object pOther=null;
The object pIndex=null;

M_pTocControl=(ITOCControl2) axTOCControl1. Object;

M_pTocControl. HitTest (e.x, e.y, pItem, ref pMap, pLayer, pOther, pIndex);
If (pItem==esriTOCControlItem. EsriTOCControlItemLayer)
{m_pTocControl. SelectItem (pLayer, null); }

M_mapControl. CustomProperty=pLayer;

If (pItem==esriTOCControlItem. EsriTOCControlItemLayer)
{m_pMenuLayer. PopupMenu (e.x, e.y, m_pTocControl hWnd); }
}
  • Related