【027】TOCControl上实现右键汇总_第1页
【027】TOCControl上实现右键汇总_第2页
【027】TOCControl上实现右键汇总_第3页
【027】TOCControl上实现右键汇总_第4页
【027】TOCControl上实现右键汇总_第5页
已阅读5页,还剩7页未读, 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

ILayerpLayer;定义个虚拟的publicILayerpLayer;定义个虚拟的publicForm2(ILayerlayer){InitializeComponent();pLayerlayer; layerpLayer,这样pLayer体了}privatevoidForm2_Load(objectsender,EventArgse){IFeatureLayerpFeatureLayer=pLayerasIFeatureLayer;IFeatureClasspFeatureClass=pFeatureLayer.FeatureClass;=false);IFeaturepFeature=pFeatureCursor.NextFeature();IFieldspFields=pFeatureClass.Fields; 1A…………ICommandSubType2A…………IToolbarMenu╠════╣ A1个 ╠══════════════════════════════════════════════════╣╚════════╝●contextMenuStri:步新建另外个窗体首先要定义ILayer。窗体要带参数,以便将ILayer传递过来。获取属性列表。DataTablepTable=newDataTablepTable=newDataTable();for(inti=0;i<pFields.FieldCount;i++){DataColumnpColumn=newDataColumn(pFields.get_Field(i).Name);pTable.Columns.Add(pColumn);}while(pFeature!=null){DataRowpRow=pTable.NewRow();for(inti0ipFields.FieldCounti++) //{pRow[i]=pFeature.get_Value(i);}pTable.Rows.Add(pRow);pFeature=pFeatureCursor.NextFeature();}dataGridView1.DataSource=pTable;}ILayerm_Layer;//沟通图层privatevoidaxTOCControl1_OnMouseDown(objectsender,ITOCControlEvents_OnMouseDownEvente){if(e.button==2){esriTOCControlItemItem=esriTOCControlItem.esriTOCControlItemNone;IBasicMappBasicMap=null;ILayerpLayer=null;objectother=null;objectindex=null;axTOCControl1.HitTest(e.x,e.y,refItem,refpBasicMap,pLayerrefotherrefindex); //实现赋m_LayerpLayer;if(Item==esriTOCControlItem.esriTOCControlItemLayer)//点击是图层话就显示ContextMenuStrip。特别注意入为“显示属性。判断在什么情况下显示。{contextMenuStrip2.Show(axTOCControl1,newSystem.Drawing.Point(e.x,e.y));}}}privatevoidToolStripMenuItem_Click(objectsender,EventArgse){Form2frmnewForm2(m_Layer); //数frm.Text="+m_Layer.Name; //frm.ShowDialog(); //}下所:╠════╣ 第A2个 ╠══════════════════════════════════════════════════╣╚════════╝第二种方法:IToolbarMenu:第一步:新建菜单框架:IToolbarMenum_TOCMapMenu=newToolbarMenu();IToolbarMenum_TOCLayerMenu=newToolbarMenu();mm_TOCLayerMenu.Caption="SubMenu"; 二级菜单设置名称m_TOCLayerMenu.AddItem(newControlsMapZoomInToolClass(),0,esriCommandStyles.esriCommandStyleIconAndText);0,false,m_TOCLayerMenu.AddItem(newControlsMapZoomInToolClass(),0,esriCommandStyles.esriCommandStyleIconAndText);1,true,m_TOCLayerMenu.AddItem(newControlsMapZoomInToolClass(),0,esriCommandStyles.esriCommandStyleIconAndText);2,false,作用在面m_TOCMapMenu.AddItem(newControlsAddDataCommandClass(),0,0,false,esriCommandStyles.esriCommandStyleIconAndText);m_TOCMapMenu.AddItem(newControlsMapFullExtentCommand(),0,1,false,esriCommandStyles.esriCommandStyleIconAndText);m_TOCMapMenu.AddItem(newControlsMapZoomInToolClass(),0,2,true,esriCommandStyles.esriCommandStyleIconAndText);m_TOCMapMenu.AddItem(newControlsMapZoomOutToolClass(),0,3,false,esriCommandStyles.esriCommandStyleIconAndText);m_TOCMapMenu.AddItem(newControlsPagePanToolClass(),0,4,false,esriCommandStyles.esriCommandStyleIconAndText);m_TOCMapMenu.AddSubMenu(m_TOCLayerMenu,5,false);m_TOCMapMenu.SetHook(axMapControl1);三步:TOCControlMouseDown事件:privatevoidaxTOCControl1_OnMouseDown(objectsender,ITOCControlEvents_OnMouseDownEvente){esriTOCControlItemitem=esriTOCControlItem.esriTOCControlItemNone;IBasicMapmap=null;ILayerlayer=null;objectother=null;objectindex=null;e.y,refitem,refmap,reflayer,refrefindex);if(e.button==2){if(item==esriTOCControlItem.esriTOCControlItemMap){}}}publicintAddItem(objectitem,intSubType,intindex,boolbeginGroup,);typeintSubTypeBaseCommandICommandSubType╠════╣ 1A╠══════════════════════════════════════════════════╣╚════════╝:Providesaccesstomembersthatdefineasubtypedcommand.MembersProvidesaccesstomembersthatdefineasubtypedcommand.MembersDescriptionGetCountThenumberofcommandsdefinedwiththisCLSID.SetSubTypeThesubtypeofthecommand.usingSystem;usingSystem.Drawing;usingSystem.Runtime.InteropServices;usingESRI.ArcGIS.ADF.BaseClasses;usingESRI.ArcGIS.ADF.CATIDs;usingESRI.ArcGIS.Controls;usingESRI.ArcGIS.Carto;usingESRI.ArcGIS.SystemUI;namespaceESRI_01{///<summary>///SummarydescriptionforScaleThresholdCmd.///</summary>[Guid("41b9d7ee-ba25-47d1-9644-f9eca4243c34")][ClassInterface(ClassInterfaceType.None)][ProgId("ESRI_01.ScaleThresholdCmd")]publicsealedclassScaleThresholdCmdICommandSubType //一个接口!{#regionCOMRegistrationFunction(s)[ComRegisterFunction()][ComVisible(false)]staticvoidRegisterFunction(TyperegisterType){//RequiredforArcGISComponentCategoryRegistrarsupport////TODO:AddanyCOMregistrationcodehere//}staticvoidUnregisterFunction(TyperegisterType){//RequiredforArcGISComponentCategoryRegistrarsupport////TODO:AddanyCOMunregistrationcodehere//}#regionArcGISComponentCategoryRegistrargeneratedcode///<summary>///RequiredmethodforArcGISComponentCategory-///Donotmodifythecontentsofthismethodwiththecodeeditor.///</summary>privatestaticvoidArcGISCategoryRegistration(TyperegisterType){stringregKey=string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}",registerType.GUID);ControlsCommands.Register(regKey);}///<summary>///RequiredmethodforArcGISComponentCategoryunregistration-///Donotmodifythecontentsofthismethodwiththecodeeditor.///</summary>privatestaticvoidArcGISCategoryUnregistration(TyperegisterType){stringregKey=string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}",registerType.GUID);ControlsCommands.Unregister(regKey);}#endregion#endregionprivateIHookHelperm_hookHelper;privateIMapControl4m_mapControl;privatelongm_subType; //publicScaleThresholdCmd(){}#regionOverridenClassMethods /////<summary>///Occurswhenthiscommandiscreated///</summary>///<paramname="hook">Instanceoftheapplication</param>///publicoverridestringCaption //{get{if(m_subType==1){return"";}elseif(m_subType==2){return"";}else{return"";}}}publicoverrideboolEnabled //{get{boolenabledtrue; //的=(ILayer)m_mapControl.CustomProperty;//n。fe) /都没设置{if((layer.MaximumScale==0)&&(layer.MinimumScale==0)){enabled=false;}}returnenabled;}}publicoverridevoidOnCreate(objecthook) //重写创建方法{if(hookisIMapControl4)(IMapControl4)hook; //给赋值}///<summary>///Occurswhenthiscommandisclicked///</summary>publicoverridevoidOnClick() //{//TODO:AddScaleThresholdCmd.OnClickimplementationIMapmap=m_mapControl.Map;ILayerlayer=m_mapControl.CustomPropertyasILayer;if(m_subType==1){map.MapScale; //1时候实现最大显示比例尺}elseif(m_subType==2){map.MapScale; //2时候实现最小显示比例尺}elseif(m_subType==3){0; //3时候去除些layer.MinimumScale=0;}}#endregion#regionICommandSubType//publicintGetCount() //{return3;}publicvoidSubType) //的SetSubType{m_subType=SubType;}#endregion}}23m_TOCLayerMenu.AddItem(newScaleThresholdCmd(),1,2,true,esriCommandStyles.esriCommandStyleTextOnly);m_TOCLayerMenu.AddItem(newScaleThresholdCmd(),2,3,false,esriCommandStyles.esriCommandStyleTextOnly);m_TOCLayerMenu.AddItem(newScaleThresholdCmd(),3,4,false,esriCommandStyles.esriCommandStyleTextOnly);m_TOCLayerMenu.SetHook(axMapControl1);╠════╣ 第2A个 ╠══════════════════════════════════════════════════╣╚════════╝口:DescriptionAddItemAddsanitemtotheToolbarMenu.AddSubMenuAddsasub-menuto

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论