×
您的位置: 首页 > 编程笔记

利用ArcGIS Engine、VS .NET和Windows控件开发GIS应用(四)

ArcGIS Windows AR 时间:2010-12-26  查看:447   收藏
摘要:

(七) PageLayoutControl添加弹出式菜单

与给跟绑定
控件协作的ToolbarControl增加ArcGIS Engine命令一样,按照前面的步骤,你也可以从ArcGIS Engine命令创建弹出式菜单。下面将向你的应用程序中增加与PageLayoutControl协作的弹出式菜单。当在PageLayoutControl可视区域点击鼠标右键的时候,弹出式菜单将显示。

1. 向类中添加如下的成员变量(红色部分):

public class Form1 : System.Windows.Forms.Form

{

private ESRI.ArcGIS.MapControl.AxMapControl axMapControl1;

private ESRI.ArcGIS.PageLayoutControl.AxPageLayoutControl axPageLayoutControl1;

private ESRI.ArcGIS.TOCControl.AxTOCControl axTOCControl1;

private ESRI.ArcGIS.ToolbarControl.AxToolbarControl axToolbarControl1;

private IToolbarMenu m_ToolbarMenu = new ToolbarMenuClass(); // 弹出式菜单

// ……

2. Form_Load事件中向ToolbarControl增加命令代码的后面加载文档代码的前面增加如下代码。

private void Form1_Load(object sender, System.EventArgs e)

{

// 前面是增加地图导航的代码……

// 共享ToolbarControl的命令池

m_ToolbarMenu.CommandPool = axToolbarControl1.CommandPool;

// ToolbarMenu增加命令

= "esriControlToolsPageLayout.ControlsPageZoomInFixedCommand";

m_progID, -1, -1, false,

esriCommandStyles.esriCommandStyleIconAndText);

= "esriControlToolsPageLayout.ControlsPageZoomOutFixedCommand";

m_progID, -1, -1, false,

esriCommandStyles.esriCommandStyleIconAndText);

= "esriControlToolsPageLayout.ControlsPageZoomWholePageCommand";

m_progID, -1, -1, false,

esriCommandStyles.esriCommandStyleIconAndText);

= "esriControlToolsPageLayout.ControlsPageZoomPageToLastExtentBackCommand";

m_progID, -1, -1, true,

esriCommandStyles.esriCommandStyleIconAndText);

= "esriControlToolsPageLayout.ControlsPageZoomPageToLastExtentForwardCommand";

m_progID, -1, -1, false,

esriCommandStyles.esriCommandStyleIconAndText);

// 设置与PageLayoutControl挂接

m_axPageLayoutControl1);

// 后面是加载图形文档的代码……

// ……

3. 在设计模式显示窗体并从属性窗口中选择axPageLayoutControl1,显示axPageLayoutControl事件。双击onMouseDown事件,向代码窗口中增加事件处理代码。

4. axPageLayoutControl1_onMouseDown事件中增加如下代码:

private void axPageLayoutControl1_onMouseDown(object sender, ESRI.ArcGIS.PageLayoutControl.IPageLayoutControlEvents_onMouseDownEvent e)

{

// 弹出ToolbarMenu

if ( e.button == 2)

{

m_e.x, e.y, axPageLayoutControl1.hWnd);

}

}

5. 生成并运行应用程序。在PageLayoutControl的显示区域单击右键以显示弹出菜单,并为页面布局导航。

(八) TOCControl中控制标签编辑

TOCControl默认允许用户自动地可见性并改变显示在目录表中的名称。你可以增加代码防止用户在编辑名称时输入空的字符串。

1. Form_Load事件的开始增加下列代码。

private void Form1_Load(object sender, System.EventArgs e)

{

// 当缩放时禁止重绘

this.SetStyle(ControlStyles.EnableNotifyMessage, true);

// 设置标签编辑为手动方式

axTOCControl1.LabelEdit = esriTOCControlEdit.esriTOCControlManual;

// 后面是加载文档代码

// ……

2. 在设计模式显示窗体并从属性窗口选择AxTOCControl1控件,显示AxTOCControl事件。双击OnEndLabelEdit向代码窗口添加事件处理函数。

3. axTOCControl1_OnEndLabelEdit事件中添加以下代码:

private void axTOCControl1_OnEndLabelEdit(object sender, ESRI.ArcGIS.TOCControl.ITOCControlEvents_OnEndLabelEditEvent e)

{

// 禁止在编辑标签时键入空字串

string newLabel = e.newLabel;

if ( newLabel.Trim() == "" )

{

e.canEdit = false;

}

}

4. 生成并生成应用程序。编辑TOCControl控件的地图、图层、标题或图例类的标签,在其上点击一次,然后再点一次调用标签编辑。试着用空字串替代标签。在编辑期间,你可以随时使用键盘上的ESC键取消编辑。

 

0% (0)
0% (0)