码迷,mamicode.com
首页 > 其他好文 > 详细

【ArcEngine 10 二次开发】ITOCControl添加鼠标右键菜单

时间:2015-05-27 12:19:28      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:arcengine

1 用contextMenuScript
首先,在ITOCControl控件中添加contextMenuScript控件,
设置好右键菜单中的Items

技术分享

然后,加入如下的代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geometry;

namespace ArcTest
{
    public partial class Form1 : Form
    {
        private ILayer m_Layer;
        public Form1()
        {
            InitializeComponent();
        }

        //TOCControl中的鼠标事件
        private void axTOCControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.ITOCControlEvents_OnMouseDownEvent e)
        {
            if (e.button == 2)
            {
                ESRI.ArcGIS.Controls.esriTOCControlItem Item = ESRI.ArcGIS.Controls.esriTOCControlItem.esriTOCControlItemNone;
                IBasicMap pBasicMap = null;
                ILayer pLayer = null;
                object other = null;
                object index = null;
                axTOCControl1.HitTest(e.x, e.y, ref Item, ref pBasicMap, ref pLayer, ref other, ref index);          //实现赋值
                m_Layer = pLayer;
                if (Item == esriTOCControlItem.esriTOCControlItemLayer)           //点击的是图层的话,就显示右键菜单
                {
                    contextMenuStrip1.Show(axTOCControl1, new System.Drawing.Point(e.x, e.y));
                    //显示右键菜单,并定义其相对控件的位置,正好在鼠标出显示
                }
            }
        }

        private void 打开属性表ToolStripMenuItem_Click(object sender, EventArgs e)
        {
             AttributesTableForm2 frm = new AttributesTableForm2(axMapControl1);
            frm.ShowDialog();
        }
    }
}

【ArcEngine 10 二次开发】ITOCControl添加鼠标右键菜单

标签:arcengine

原文地址:http://blog.csdn.net/gdp12315_gu/article/details/46044089

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!