027TOCControl上实现右键Word下载.docx

上传人:b****7 文档编号:21992387 上传时间:2023-02-02 格式:DOCX 页数:16 大小:74.32KB
下载 相关 举报
027TOCControl上实现右键Word下载.docx_第1页
第1页 / 共16页
027TOCControl上实现右键Word下载.docx_第2页
第2页 / 共16页
027TOCControl上实现右键Word下载.docx_第3页
第3页 / 共16页
027TOCControl上实现右键Word下载.docx_第4页
第4页 / 共16页
027TOCControl上实现右键Word下载.docx_第5页
第5页 / 共16页
点击查看更多>>
下载资源
资源描述

027TOCControl上实现右键Word下载.docx

《027TOCControl上实现右键Word下载.docx》由会员分享,可在线阅读,更多相关《027TOCControl上实现右键Word下载.docx(16页珍藏版)》请在冰豆网上搜索。

027TOCControl上实现右键Word下载.docx

∙首先要定义一个全局变量ILayer。

∙窗体要带参数,以便将ILayer传递过来。

∙获取属性列表。

ILayerpLayer;

//定义一个虚拟的ILayer

publicForm2(ILayerlayer)

{

InitializeComponent();

pLayer=layer;

//将赋值的layer再赋值给pLayer,这样pLayer就是实体了

}

privatevoidForm2_Load(objectsender,EventArgse)

IFeatureLayerpFeatureLayer=pLayerasIFeatureLayer;

IFeatureClasspFeatureClass=pFeatureLayer.FeatureClass;

IFeatureCursorpFeatureCursor=pFeatureClass.Search(null,false);

IFeaturepFeature=pFeatureCursor.NextFeature();

IFieldspFields=pFeatureClass.Fields;

DataTablepTable=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();

i++)//添加每一列的值

pRow[i]=pFeature.get_Value(i);

pTable.Rows.Add(pRow);

pFeature=pFeatureCursor.NextFeature();

dataGridView1.DataSource=pTable;

第二步:

建立右键菜单项

∙添加一个ContextMenuStrip控件,然后增加几个菜单项。

∙特别注意加入一个菜单项为“显示属性”。

∙判断在什么情况下显示右键菜单。

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,refpLayer,refother,refindex);

//实现赋值

m_Layer=pLayer;

if(Item==esriTOCControlItem.esriTOCControlItemLayer)//点击的是图层的话,就显示右键菜单

contextMenuStrip2.Show(axTOCControl1,newSystem.Drawing.Point(e.x,e.y));

//显示右键菜单,并定义其相对控件的位置,正好在鼠标出显示

privatevoid显示属性ToolStripMenuItem_Click(objectsender,EventArgse)

Form2frm=newForm2(m_Layer);

//定义窗体,注意窗体的参数

frm.Text="

Attributesof"

+m_Layer.Name;

//显示标题

frm.ShowDialog();

//以对话框形式显示窗体

效果如下所示:

第A2个 

IToolbarMenu:

新建菜单框架:

IToolbarMenum_TOCMapMenu=newToolbarMenu();

IToolbarMenum_TOCLayerMenu=newToolbarMenu();

在菜单框架中加入菜单项,用AddItem方法实现:

m_TOCLayerMenu.Caption="

SubMenu"

;

//二级菜单设置名称

m_TOCLayerMenu.AddItem(newControlsMapZoomInToolClass(),0,0,false,esriCommandStyles.esriCommandStyleIconAndText);

m_TOCLayerMenu.AddItem(newControlsMapZoomInToolClass(),0,1,true,esriCommandStyles.esriCommandStyleIconAndText);

m_TOCLayerMenu.AddItem(newControlsMapZoomInToolClass(),0,2,false,esriCommandStyles.esriCommandStyleIconAndText);

m_TOCLayerMenu.SetHook(axMapControl1);

//作用在MapControl上面

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);

第三步:

TOCControl的MouseDown事件:

privatevoidaxTOCControl1_OnMouseDown(objectsender,ITOCControlEvents_OnMouseDownEvente)

{

esriTOCControlItemitem=esriTOCControlItem.esriTOCControlItemNone;

IBasicMapmap=null;

ILayerlayer=null;

axTOCControl1.HitTest(e.x,e.y,refitem,refmap,reflayer,refother,refindex);

if(item==esriTOCControlItem.esriTOCControlItemMap)

axTOCControl1.SelectItem(map,null);

m_TOCMapMenu.PopupMenu(e.x,e.y,axTOCControl1.hWnd);

}

实现效果如下:

publicintAddItem(

objectitem,

intSubType,

intindex,

boolbeginGroup,

esriCommandStylesStyle

);

第一个参数:

菜单项的内容,功能实现。

第二个参数:

对于一个工具定义多个type的时候,才会用到,每一个int代表一个新的实现。

第三个参数:

索引值,在菜单项上面显示的位置。

默认为-1,按书写顺序排序。

第四个参数:

是否开始一个新组,就是在其上面有一个“——”的效果。

第五个参数:

显示样式。

用SubType实现:

首先:

建立工具,这个时候类不仅要继承BaseCommand类,还要继承ICommandSubType接口

第1A个 

ICommandSubType接口:

  Providesaccesstomembersthatdefineasubtypedcommand.

  Members

Description

GetCount

ThenumberofcommandsdefinedwiththisCLSID.

SetSubType

Thesubtypeofthecommand.

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"

publicsealedclassScaleThresholdCmd:

BaseCommand,ICommandSubType  //要多继承一个接口!

#regionCOMRegistrationFunction(s)

[ComRegisterFunction()]

[ComVisible(false)]

staticvoidRegisterFunction(TyperegisterType)

//RequiredforArcGISComponentCategoryRegistrarsupport

ArcGISCategoryRegistration(registerType);

//

//TODO:

AddanyCOMregistrationcodehere

[ComUnregisterFunction()]

staticvoidUnregisterFunction(TyperegisterType)

ArcGISCategoryUnregistration(registerType);

AddanyCOMunregistrationcodehere

#regionArcGISComponentCategoryRegistrargeneratedcode

///RequiredmethodforArcGISComponentCategoryregistration-

///Donotmodifythecontentsofthismethodwiththecodeeditor.

privatestaticvoidArcGISCategoryRegistration(TyperegisterType)

stringregKey=string.Format("

HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}"

registerType.GUID);

ControlsCommands.Register(regKey);

///RequiredmethodforArcGISComponentCategoryunregistration-

privatestaticvoidArcGISCategoryUnregistration(TyperegisterType)

ControlsCommands.Unregister(regKey);

#endregion

privateIHookHelperm_hookHelper;

privateIMapControl4m_mapControl;

privatelongm_subType;

    //用来分类的

publicScaleThresholdCmd()

#regionOverridenClassMethods  //重写的方法

///Occurswhenthiscommandiscreated

paramname="

hook"

>

Instanceoftheapplication<

/param>

///

publicoverridestringCaption  //重写标题

get

if(m_subType==1)

return"

设置最大显示比例尺"

elseif(m_subType==2)

设置最小显示比例尺"

else

取消比例尺显示限制"

publicoverrideboolEnabled  //重写Enabled属性

boolenabled=true;

    //默认情况下都是true的

ILayerlayer=(ILayer)m_mapControl.CustomProperty;

  //获取所指的layer,在MouseDown事件中有获取到这个layer。

if(m_subType==3)  //如果选择的是3,且最大和最小比例尺都没有设置,则为false!

if((layer.MaximumScale==0)&

&

(layer.MinimumScale==0))

enabled=false;

returnenabled;

publicoverridevoidOnCreate(objecthook)  //重写创建方法

if(hookisIMapControl4)

m_mapControl=(IMapControl4)hook;

  //给m_mapControl赋值

///Occurswhenthiscommandisclicked

publicoverridevoidOnClick()  //重写单击方法

AddScaleThresholdCmd.OnClickimplementation

IMapmap=m_mapControl.Map;

ILayerlayer=m_mapControl.CustomPropertyasILayer;

layer.MaximumScale=map.MapScale;

  //为1的时候,实现最大显示比例尺

layer.MinimumScale=map.MapScale;

  //为2的时候,实现最小显示比例尺

elseif(m_subType==3)

layer.MaximumScale=0;

    //为3的时候,去除这些

layer.MinimumScale=0;

#regionICommandSubType成员  //继承接口的话,就一定要实现接口了!

publicintGetCount()    //重写ICommandSubType的GetCount方法

return3;

publicvoidSetSubType(intSubType)  //重写ICommandSubType的SetSubType方法

m_subType=SubType;

最后通过下面的1、2、3来实现即可!

m_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);

第2A个 

IToolbarMenu

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 农学

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

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