标签:style blog http io os ar for sp 2014
最近参考Arcengine的Samples做的功能,虽然简单,但是示例代码的确体现出了很好的封装性,值得学习,效果图如下:
闲话休絮,直入正题:
一、首先建立工具类,实现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的索引位置
标签:style blog http io os ar for sp 2014
原文地址:http://www.cnblogs.com/GiserNet/p/4025235.html