ImageVerifierCode 换一换
格式:DOCX , 页数:39 ,大小:20.07KB ,
资源ID:11432767      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/11432767.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(027TOCControl上实现右键.docx)为本站会员(b****7)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

027TOCControl上实现右键.docx

1、027TOCControl上实现右键【027 】TOCControl 上实现右键-目录:A1 第一种方法: contextMenuStripA2 第二种方法: IToolbarMenu1AICommandSubType接口2AIToolbarMenu接口-第 A1 个第一种方法:contextMenuStrip:第一步:新建另外一个窗体首先要定义一个全局变量窗体要带参数,以便将ILayer ILayer。传递过来。获取属性列表。ILayer pLayer;/定义一个虚拟的ILayerpublicForm2(ILayer layer)InitializeComponent();pLayer =

2、layer;/将赋值的layer再赋值给pLayer,这样pLayer就是实体了privatevoidForm2_Load( objectsender, EventArgs e)IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, false);IFeature pFeature = pFeatureCursor

3、.NextFeature();IFields pFields = pFeatureClass.Fields;DataTable pTable =new DataTable();for ( int i =0; i pFields.FieldCount; i+)/获取所有列DataColumn pColumn = pTable.Columns.Add(pColumn);new DataColumn(pFields.get_Field(i).Name);while(pFeature !=null)DataRow pRow = pTable.NewRow();for ( int i = 0; i pF

4、ields.FieldCount; i+)/添加每一列的值pRowi = pFeature.get_Value(i);pTable.Rows.Add(pRow);pFeature = pFeatureCursor.NextFeature();dataGridView1.DataSource = pTable;第二步:建立右键菜单项添加一个 ContextMenuStrip 控件,然后增加几个菜单项。特别注意加入一个菜单项为 “显示属性 ”。判断在什么情况下显示右键菜单。ILayer m_Layer; / 沟通图层private void axTOCControl1_OnMouseDown( o

5、bjectITOCControlEvents_OnMouseDownEvent e)sender,if(e.button =2)esriTOCControlItem Item =esriTOCControlItem.esriTOCControlItemNone;IBasicMap pBasicMap =ILayer pLayer = nullobject other = nullobject index = nullaxTOCControl1.HitTest(e.x, e.y,pLayer, ref other, ref index);m_Layer = pLayer;null;ref/ 实现

6、赋值Item,refpBasicMap,refif(Item = esriTOCControlItem.esriTOCControlItemLayer)/点击的是图层的话,就显示右键菜单contextMenuStrip2.Show(axTOCControl1, new System.Drawing.Point(e.x, e.y);/ 显示右键菜单,并定义其相对控件的位置,正好在鼠标出显示privatevoid显示属性ToolStripMenuItem_Click(objectsender,EventArgs e)Form2 frm =new Form2(m_Layer);/ 定义窗体,注意窗体

7、的参数frm.Text =Attributes of + m_Layer.Name;/ 显示标题frm.ShowDialog();/ 以对话框形式显示窗体效果如下所示:- 第 A2 个 第二种方法: IToolbarMenu :第一步:新建菜单框架:IToolbarMenu m_TOCMapMenu = new ToolbarMenu();IToolbarMenu m_TOCLayerMenu= new ToolbarMenu();第二步:在菜单框架中加入菜单项,用AddItem方法实现:m_TOCLayerMenu.Caption =Sub Menu ;/二级菜单设置名称m_TOCLayer

8、Menu.AddItem(new ControlsMapZoomInToolClass(),0,0,false,esriCommandStyles.esriCommandStyleIconAndText);m_TOCLayerMenu.AddItem(new ControlsMapZoomInToolClass(),0,1,true,esriCommandStyles.esriCommandStyleIconAndText);m_TOCLayerMenu.AddItem(new ControlsMapZoomInToolClass(),0,2,false,esriCommandStyles.e

9、sriCommandStyleIconAndText);m_TOCLayerMenu.SetHook(axMapControl1);/作用在 MapControl上面m_TOCMapMenu.AddItem(new ControlsAddDataCommandClass(),0,0,false,esriCommandStyles.esriCommandStyleIconAndText);m_TOCMapMenu.AddItem(new ControlsMapFullExtentCommand(),0,1, false,esriCommandStyles.esriCommandStyleIcon

10、AndText);m_TOCMapMenu.AddItem(new ControlsMapZoomInToolClass(),0, 2,true,esriCommandStyles.esriCommandStyleIconAndText);m_TOCMapMenu.AddItem(new ControlsMapZoomOutToolClass(),0,3,false,esriCommandStyles.esriCommandStyleIconAndText);m_TOCMapMenu.AddItem(new ControlsPagePanToolClass(),0,4 ,false,esriC

11、ommandStyles.esriCommandStyleIconAndText);m_TOCMapMenu.AddSubMenu(m_TOCLayerMenu,5, false);m_TOCMapMenu.SetHook(axMapControl1);第三步: TOCControl 的 MouseDown 事件:private void axTOCControl1_OnMouseDown( object ITOCControlEvents_OnMouseDownEvent e)sender,esriTOCControlItem item =esriTOCControlItem.esriTOC

12、ControlItemNone;IBasicMap map = null ;ILayer layer = null ;object other = null ;object index = null ;axTOCControl1.HitTest(e.x,e.y,refitem, refmap, reflayer,refother,ref index);if(e.button =2 )if(item =esriTOCControlItem.esriTOCControlItemMap)axTOCControl1.SelectItem(map,null );m_TOCMapMenu.PopupMen

13、u(e.x, e.y, axTOCControl1.hWnd);实现效果如下:public int AddItem (object item,int SubType,int index,bool beginGroup,esriCommandStyles Style);第一个参数:菜单项的内容,功能实现。第二个参数:对于一个工具定义多个 type 的时候,才会用到,每一个 int 代表一个新的实现。第三个参数:索引值,在菜单项上面显示的位置。默认为 -1 ,按书写顺序排序。第四个参数:是否开始一个新组,就是在其上面有一个 “”的效果。第五个参数:显示样式。用 SubType 实现:首先:建立工具

14、,这个时候类不仅要继承 BaseCommand 类,还要继承ICommandSubType 接口- 第 1A 个 ICommandSubType 接口:Provides access to members that define a subtyped command.MembersDescriptionGetCountThe number of commands defined with this CLSID.SetSubTypeThe subtype of the command.usingusingusingusingusingusingusingusingSystem;System.Dr

15、awing;System.Runtime.InteropServices;ESRI.ArcGIS.ADF.BaseClasses;ESRI.ArcGIS.ADF.CATIDs;ESRI.ArcGIS.Controls;ESRI.ArcGIS.Carto;ESRI.ArcGIS.SystemUI;namespace ESRI_01/Summary description for ScaleThresholdCmd./Guid(41b9d7ee-ba25-47d1-9644-f9eca4243c34)ClassInterface(ClassInterfaceType.None)ProgId(ESR

16、I_01.ScaleThresholdCmd)publicsealedclassScaleThresholdCmd : BaseCommand,ICommandSubType/ 要多继承一个接口!#region COM Registration Function(s)ComRegisterFunction()ComVisible( false )static void RegisterFunction(Type registerType)/ Required for ArcGIS ComponentCategoryRegistrarsupportArcGISCategoryRegistrati

17、on(registerType);/ TODO: Add any COM registration code here/ComUnregisterFunction()ComVisible( false )static void UnregisterFunction(Type registerType)/ Required for ArcGIS ComponentCategoryRegistrarsupportArcGISCategoryUnregistration(registerType);/ TODO: Add any COM unregistration code here/#regio

18、n ArcGIS Component Category Registrar generated code/Required method for ArcGIS Component Category registration-/Do not modify the contents of this method with the codeeditor./private staticvoidArcGISCategoryRegistration(TyperegisterType)string regKey =string .Format( HKEY_CLASSES_ROOTCLSID0register

19、Type.GUID);ControlsCommands.Register(regKey);,/Required method for ArcGIS Component Categoryunregistration -/Do not modify the contents of this method with the codeeditor./private staticvoidArcGISCategoryUnregistration(TyperegisterType)string regKey =string .Format( HKEY_CLASSES_ROOTCLSID0registerTy

20、pe.GUID);ControlsCommands.Unregister(regKey);,#endregion#endregionprivateprivateprivateIHookHelper m_hookHelper; IMapControl4 m_mapControl; long m_subType;/ 用来分类的publicScaleThresholdCmd()#region Overriden Class Methods / 重写的方法/Occurs when this command is created/ Instance of the application/public o

21、verride string Caption / 重写标题getif(m_subType =1)return 设置最大显示比例尺 ;elseif(m_subType =2)return 设置最小显示比例尺 ;elsereturn 取消比例尺显示限制 ;public override bool Enabled / 重写 Enabled 属性getbool enabled = true ; / 默认情况下都是 trueILayer layer = (ILayer)m_mapControl.CustomProperty;/ 获取所指的 layer ,在 MouseDown 事件中有获取到这个 lay

22、er 。的没有设置,则为iffalse(m_subType =!3)/ 如果选择的是3 ,且最大和最小比例尺都if(layer.MaximumScale =0 ) & (layer.MinimumScale =0)enabled= false;return enabled;publicoverridevoidOnCreate(objecthook)/ 重写创建方法if (hookm_mapControlisIMapControl4)= (IMapControl4)hook;/ 给m_mapControl赋值/Occurs when this command is clicked/public

23、override void OnClick()/ 重写单击方法/ TODO: Add ScaleThresholdCmd.OnClick implementationIMap map = m_mapControl.Map;ILayer layer = m_mapControl.CustomProperty as ILayer;if (m_subType = 1 )layer.MaximumScale= map.MapScale;/ 为1的时候,实现最大显示比例尺elseif(m_subType =2)layer.MinimumScale= map.MapScale;/ 为2的时候,实现最小显示比例尺

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1