027TOCControl上实现右键.docx

上传人:b****3 文档编号:5920188 上传时间:2023-05-09 格式:DOCX 页数:39 大小:20.07KB
下载 相关 举报
027TOCControl上实现右键.docx_第1页
第1页 / 共39页
027TOCControl上实现右键.docx_第2页
第2页 / 共39页
027TOCControl上实现右键.docx_第3页
第3页 / 共39页
027TOCControl上实现右键.docx_第4页
第4页 / 共39页
027TOCControl上实现右键.docx_第5页
第5页 / 共39页
027TOCControl上实现右键.docx_第6页
第6页 / 共39页
027TOCControl上实现右键.docx_第7页
第7页 / 共39页
027TOCControl上实现右键.docx_第8页
第8页 / 共39页
027TOCControl上实现右键.docx_第9页
第9页 / 共39页
027TOCControl上实现右键.docx_第10页
第10页 / 共39页
027TOCControl上实现右键.docx_第11页
第11页 / 共39页
027TOCControl上实现右键.docx_第12页
第12页 / 共39页
027TOCControl上实现右键.docx_第13页
第13页 / 共39页
027TOCControl上实现右键.docx_第14页
第14页 / 共39页
027TOCControl上实现右键.docx_第15页
第15页 / 共39页
027TOCControl上实现右键.docx_第16页
第16页 / 共39页
027TOCControl上实现右键.docx_第17页
第17页 / 共39页
027TOCControl上实现右键.docx_第18页
第18页 / 共39页
027TOCControl上实现右键.docx_第19页
第19页 / 共39页
027TOCControl上实现右键.docx_第20页
第20页 / 共39页
亲,该文档总共39页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

027TOCControl上实现右键.docx

《027TOCControl上实现右键.docx》由会员分享,可在线阅读,更多相关《027TOCControl上实现右键.docx(39页珍藏版)》请在冰点文库上搜索。

027TOCControl上实现右键.docx

027TOCControl上实现右键

 

【027】TOCControl上实现右键

 

---------------------------------------------------------------------------------------

------------------

 

●·●目录:

A1

第一种方法:

contextMenuStrip

A2

第二种方法:

IToolbarMenu

1A

ICommandSubType接口

2A

IToolbarMenu

接口

---------------------------------------------------------------------------------------

------------------

╔════════╗

╠════╣第A1个

╠══════════════════════════

════════════════════════╣

╚════════╝

●·●第一种方法:

contextMenuStrip

第一步:

新建另外一个窗体

 

首先要定义一个全局变量窗体要带参数,以便将

 

ILayerILayer

 

传递过来。

获取属性列表。

 

ILayerpLayer;

 

//

 

定义一个虚拟的

 

ILayer

public

Form2(ILayerlayer)

{

InitializeComponent();

pLayer=layer;

//

将赋值的

layer

再赋值给

pLayer

,这样

pLayer

}

就是实体了

 

private

 

void

 

Form2_Load(object

 

sender,EventArgse)

{

IFeatureLayerpFeatureLayer=pLayerasIFeatureLayer;

IFeatureClasspFeatureClass=pFeatureLayer.FeatureClass;

IFeatureCursorpFeatureCursor=pFeatureClass.Search(

null

false

);

IFeaturepFeature=pFeatureCursor.NextFeature();

IFieldspFields=pFeatureClass.Fields;

 

DataTablepTable=

 

newDataTable();

 

for(inti=

0;i

//

获取所有列

{

DataColumnpColumn=pTable.Columns.Add(pColumn);

newDataColumn(pFields.get_Field(i).Name);

}

while

(pFeature!

=

null

{

DataRowpRow=pTable.NewRow();

for(inti=0;i

 

//

 

添加每一

列的值

{

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

}

pTable.Rows.Add(pRow);

pFeature=pFeatureCursor.NextFeature();

}

dataGridView1.DataSource=pTable;

}

 

第二步:

建立右键菜单项

 

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

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

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

 

ILayerm_Layer;//沟通图层

privatevoidaxTOCControl1_OnMouseDown(object

ITOCControlEvents_OnMouseDownEvente)

 

sender,

{

if

(e.button==

2)

{

esriTOCControlItemItem=

esriTOCControlItem.esriTOCControlItemNone;

IBasicMappBasicMap=

ILayerpLayer=null

objectother=null

objectindex=null

axTOCControl1.HitTest(e.x,e.y,

pLayer,refother,refindex);

m_Layer=pLayer;

 

;

;

;

 

null

 

;

 

ref

//实现赋值

 

Item,

 

ref

 

pBasicMap,

 

ref

if

(Item==esriTOCControlItem.esriTOCControlItemLayer)

//点击的是图层的话,就显示右键菜单

 

{

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

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

}

}

 

}

 

private

 

void

 

显示属性

 

ToolStripMenuItem_Click(

 

object

 

sender,

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(objectITOCControlEvents_OnMouseDownEvente)

 

sender,

{

esriTOCControlItemitem=

esriTOCControlItem.esriTOCControlItemNone;

IBasicMapmap=null;

ILayerlayer=null;

objectother=null;

objectindex=null;

 

axTOCControl1.HitTest(e.x,

 

e.y,

 

ref

 

item,ref

 

map,ref

 

layer,

 

ref

 

other,

refindex);

 

if

 

(e.button==

 

2)

{

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.

 

using

using

using

using

using

using

using

using

 

System;

System.Drawing;

System.Runtime.InteropServices;

ESRI.ArcGIS.ADF.BaseClasses;

ESRI.ArcGIS.ADF.CATIDs;

ESRI.ArcGIS.Controls;

ESRI.ArcGIS.Carto;

ESRI.ArcGIS.SystemUI;

 

namespaceESRI_01

{

///

///SummarydescriptionforScaleThresholdCmd.

///

[Guid(

"41b9d7ee-ba25-47d1-9644-f9eca4243c34"

)]

[ClassInterface(ClassInterfaceType.None)]

[ProgId(

"ESRI_01.ScaleThresholdCmd"

)]

public

sealed

class

ScaleThresholdCmd:

BaseCommand,

ICommandSubType

//要多继承一个接口!

{

#regionCOMRegistrationFunction(s)

[ComRegisterFunction()]

[ComVisible(false)]

staticvoidRegisterFunction(TyperegisterType)

{

//RequiredforArcGISComponent

Category

Registrar

support

ArcGISCategoryRegistration(registerType);

 

//

//TODO:

AddanyCOMregistrationcodehere

//

 

}

 

[ComUnregisterFunction()]

[ComVisible(false)]

staticvoidUnregisterFunction(TyperegisterType)

{

//RequiredforArcGISComponent

Category

Registrar

support

ArcGISCategoryUnregistration(registerType);

 

//

//TODO:

AddanyCOMunregistrationcodehere

//

}

 

#regionArcGISComponentCategoryRegistrargeneratedcode

///

///RequiredmethodforArcGISComponentCategoryregistration

-

///Donotmodifythecontentsofthismethodwiththecode

editor.

///

privatestatic

void

ArcGISCategoryRegistration(Type

registerType)

{

stringregKey=

string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}"

registerType.GUID);

ControlsCommands.Register(regKey);

 

 

}

///

///RequiredmethodforArcGISComponentCategory

unregistration-

///Donotmodifythecontentsofthismethodwiththecode

editor.

///

privatestatic

void

ArcGISCategoryUnregistration(Type

registerType)

{

stringregKey=

string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}"

registerType.GUID);

ControlsCommands.Unregister(regKey);

 

 

}

 

#endregion

#endregion

 

private

private

private

 

IHookHelperm_hookHelper;IMapControl4m_mapControl;longm_subType;

 

//用来分类的

public

ScaleThresholdCmd()

{

}

 

#regionOverridenClassMethods//重写的方法

 

///

///Occurswhenthiscommandiscreated

///

///

Instanceoftheapplication

///

 

publicoverridestringCaption//重写标题

{

get

{

if

(m_subType==

1)

{

return

"设置最大显示比例尺

";

}

else

if

(m_subType==

2)

{

return

"设置最小显示比例尺

";

}

else

{

return

"取消比例尺显示限制

";

}

}

}

 

publicoverrideboolEnabled//重写Enabled属性

{

get

{

 

boolenabled=true;//默认情况下都是true

ILayerlayer=(ILayer)m_mapControl.CustomProperty;

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

 

 

没有设置,则为

if

false

(m_subType==

3)

//如果选择的是

3,且最大和最小比例尺都

{

if

((layer.MaximumScale==

0)&&(layer.MinimumScale==

0))

{

enabled

=false

;

}

}

returnenabled;

}

}

 

public

 

override

 

void

 

OnCreate(

 

object

 

hook)

 

//重写创建方法

{

if(hook

m_mapControl

is

IMapControl4)

=(IMapControl4)hook;

 

//给

 

m_mapControl

赋值

}

 

///

///Occurswhenthiscommandisclicked

///

publicoverridevoidOnClick()

//重写单击方法

{

//TODO:

AddScaleThresholdCmd.OnClickimplementation

IMapmap=m_mapControl.Map;

ILayerlayer=m_mapControl.CustomPropertyasILayer;

if(m_subType==1)

{

layer.MaximumScale

=map.MapScale;

//为

1

的时候,实

现最大显示比例尺

}

else

if

(m_subType==

2)

{

layer.MinimumScale

=map.MapScale;

//为

2

的时候,实

现最小显示比例尺

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

当前位置:首页 > PPT模板 > 商务科技

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2