TreeList控件右键菜单功能的实现

<p>TreeList控件实现右键菜单功能,其实跟TocControl控件实现原理是一样的,TocControl也是利用一个ContextMenu控件,利用HitT方法,TreeList利用其ContextMenuStrip属性就可以。</p><p>TocControl实现右键功能:</p>
 private void MenuList_MouseDown(object sender, MouseEventArgs e)
        {
            //绑定右键菜单
            if (e.Button == MouseButtons.Right)
            {
                MenuList.ContextMenu = null;
                TreeListHitInfo hInfo = MenuList.CalcHitInfo(new Point(e.X, e.Y));
                TreeListNode node = hInfo.Node;
                MenuList.FocusedNode = node;
                if (node != null)
                {
                    MenuList.ContextMenuStrip = contextMenu;
                }
            }
        }


TreeList实现右键功能:

  private void axTOCControl_OnMouseDown_1(object sender, ITOCControlEvents_OnMouseDownEvent e)
        {

            if (e.button == 2)
            {
                esriTOCControlItem item = esriTOCControlItem.esriTOCControlItemNone;
                IBasicMap m_BasicMap = null;
                ILayer m_Layer = null;
                object other = null;
                object index = null;
                axTOCControl.HitTest(e.x, e.y, ref item, ref m_BasicMap, ref m_Layer, ref other, ref index);
                g_Layer = m_Layer;
                if (item == esriTOCControlItem.esriTOCControlItemLayer)
                {
                    cMStoc.Show(axTOCControl, new System.Drawing.Point(e.x, e.y));
                }
            }
        }

 

 


 

posted @ 2014-06-29 10:05  静以养身 俭以养德  阅读(296)  评论(0编辑  收藏  举报