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

toolControls添加工具项

时间:2014-10-14 23:28:09      阅读:374      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   os   ar   for   sp   2014   

最近参考Arcengine的Samples做的功能,虽然简单,但是示例代码的确体现出了很好的封装性,值得学习,效果图如下:

 

bubuko.com,布布扣

闲话休絮,直入正题:

  一、首先建立工具类,实现IMenuDef接口

class Neval:IMenuDef//这个接口
    {

        public string Caption
        {
            get
            {
                return "Navigation";
            }
        }

        public void GetItemInfo(int pos, IItemDef itemDef)      //POS为序列号
        {
            switch (pos)
            {
                case 0:
                    itemDef.ID = "esriControls.ControlsMapZoomInFixedCommand";     //就是ESRI.ArcGIS.Controls下的类的名称
                    break;
                case 1:
                    itemDef.ID = "esriControls.ControlsMapZoomOutFixedCommand";
                    break;
                case 2:
                    itemDef.ID = "esriControls.ControlsMapFullExtentCommand";
                    itemDef.Group = true;
                    break;
                case 3:
                    itemDef.ID = "esriControls.ControlsMapZoomToLastExtentBackCommand";
                    break;
                case 4:
                    itemDef.ID = "esriControls.ControlsMapZoomToLastExtentForwardCommand";
                    break;
            }
        }

        public int ItemCount
        {
            get {
                return 5;
            }
        }

        public string Name
        {
            get { return "Navigation"; }
        }
    }

二、在form—load中添加

axToolbarControl1.AddItem(new Neval(), -1, -1, false, 0, esriCommandStyles.esriCommandStyleIconAndText);

三、再创建类SubMenu同样实现IMenuDef接口

 class SubMenu:IMenuDef
    {

        public string Caption
        {
            get { return "SumMenu"; }
        }

        public void GetItemInfo(int pos, IItemDef itemDef)
        {
            switch (pos)
            {
                case 0:
                    itemDef.ID = "esriContorls.ControlsSelectTool";
                    break;
                case 1:
                    itemDef.ID = "esriControls.ControlsSendBackwardCommand";
                    break;
                case 2:
                    itemDef.ID = "esriControls.ControlsSnappingEnabledCommand";
                    break;
            }
        }

        public int ItemCount
        {
            get {return 3; }
        }

        public string Name
        {
            get { return "SumMenu"; }
        }
    }

 

四、在Form_load()添加如下代码:

 IToolbarItem items = axToolbarControl1.GetItem(4); //4为所在工具的索引
            IToolbarMenu menu = items.Menu;
            menu.AddSubMenu(new SubMenu(), 2, true);//2为插入SubMenu的索引位置

toolControls添加工具项

标签:style   blog   http   io   os   ar   for   sp   2014   

原文地址:http://www.cnblogs.com/GiserNet/p/4025235.html

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