博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ArcEngine开发之自定义工具
阅读量:4648 次
发布时间:2019-06-09

本文共 4058 字,大约阅读时间需要 13 分钟。

1.在项目中添加基于Base Command等的类,可改变命名空间名称。

2.引用:命名空间.类名称;

实例:

using System;

using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Resources;
using System.Reflection;

using System.Drawing;

using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.ADF.CATIDs;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;

namespace CSharpMyFullExtent

{
/// <summary>
/// Command that works in ArcMap/Map/PageLayout
/// </summary>
[Guid("4f4e73b1-40c3-44a5-8729-d403b7b3d779")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("CSharpMyFullExtent.MyFullExtentCommand")]
public sealed class MyFullExtentCommand : BaseCommand
{
#region COM Registration Function(s)
[ComRegisterFunction()]
[ComVisible(false)]
static void RegisterFunction(Type registerType)
{
// Required for ArcGIS Component Category Registrar support
ArcGISCategoryRegistration(registerType);

//

// TODO: Add any COM registration code here
//
}

[ComUnregisterFunction()]

[ComVisible(false)]
static void UnregisterFunction(Type registerType)
{
// Required for ArcGIS Component Category Registrar support
ArcGISCategoryUnregistration(registerType);

//

// TODO: Add any COM unregistration code here
//
}

#region ArcGIS Component Category Registrar generated code

/// <summary>
/// Required method for ArcGIS Component Category registration -
/// Do not modify the contents of this method with the code editor.
/// </summary>
private static void ArcGISCategoryRegistration(Type registerType)
{
string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{
{
{0}}}", registerType.GUID);
MxCommands.Register(regKey);
ControlsCommands.Register(regKey);
}
/// <summary>
/// Required method for ArcGIS Component Category unregistration -
/// Do not modify the contents of this method with the code editor.
/// </summary>
private static void ArcGISCategoryUnregistration(Type registerType)
{
string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{
{
{0}}}", registerType.GUID);
MxCommands.Unregister(regKey);
ControlsCommands.Unregister(regKey);
}

#endregion

#endregion

private IHookHelper m_hookHelper = null;

public MyFullExtentCommand()
{
//
// TODO: Define values for the public properties
//
base.m_category = "CustomCommands"; //localizable text
base.m_caption = "My Full Extent"; //localizable text
base.m_message = "My Full Extent"; //localizable text
base.m_toolTip = "My Full Extent"; //localizable text
base.m_name = "MyCommands_MyFullExtent"; //unique id, non-localizable (e.g. "MyCategory_MyCommand")

//As part of your deployment strategy you must register the name of the WinHelp file (*.hlp)

//as a new string value in: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Help
//or provide the full path name.
base.m_helpFile = "MyHelpFile.hlp";

//The Context Help ID as defined when compiling the RTF file into the HelpFile

base.m_helpID = 1234;

ResourceManager rm = new ResourceManager("CSharpMyFullExtent.Resources", Assembly.GetExecutingAssembly());

base.m_bitmap = (System.Drawing.Bitmap)rm.GetObject("CommandImage");
}

#region Overriden Class Methods

/// <summary>

/// Occurs when this command is created
/// </summary>
/// <param name="hook">Instance of the application</param>
public override void OnCreate(object hook)
{
if (hook == null)
return;

try

{
m_hookHelper = new HookHelperClass();
m_hookHelper.Hook = hook;
if (m_hookHelper.ActiveView == null)
m_hookHelper = null;
}
catch
{
m_hookHelper = null;
}

if (m_hookHelper == null)

base.m_enabled = false;
else
base.m_enabled = true;

}

/// <summary>

/// Occurs when this command is clicked
/// </summary>
public override void OnClick()
{
//Get IActiveView interface
IActiveView pActiveView = m_hookHelper.FocusMap as IActiveView;

//Set the extent to the full extent

pActiveView.Extent = pActiveView.FullExtent;

//Refresh the active view

pActiveView.Refresh();
}

#endregion

}
}

 

引用:

axToolbarControl1.AddItem("CSharpMyFullExtent.MyFullExtentCommand", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly);

转载于:https://www.cnblogs.com/jinqier/archive/2013/01/22/2871148.html

你可能感兴趣的文章
JS 心得总结
查看>>
WINDOWS 下安装boost
查看>>
Log4j(1)--hellloworld
查看>>
java中equals和 == 的区别
查看>>
greenDao 3.0基础
查看>>
CSS自学笔记(15):CSS3多列布局
查看>>
Objective-C ,ios,iphone开发基础:ios数据库(The SQLite Database),使用终端进行简单的数据库操作...
查看>>
CSS媒体查询,CSS根据不同的分辨率显示不同的样式
查看>>
丹佛机场行李系统Postmortem
查看>>
好吧,如果一定要RESTFUL的DJANGO
查看>>
Java类的执行顺序
查看>>
Why ngx-uploader doesn't like to cooperate with .net core 2.x?
查看>>
iOS-Senior20-Map定位
查看>>
Apache本地环境部署
查看>>
开发模式接入
查看>>
java 中的复制(将D盘中的文件复制到E盘中)
查看>>
【原创】谈谈redis的热key问题如何解决
查看>>
LoadLibrary 失败 GetLastError 126
查看>>
Monty Hall 问题与贝叶斯定理的理解
查看>>
利用JavaScript的字符串操作实现简单查字
查看>>