概要:在使用ArcEngine开发中,给ToolbarControl添加按钮形式的命令项相信大家都很熟悉了,因为网上的例子很多。但这种使用click调用功能的方式只能满足大部分用户在体验方面的需求,除此之外用户很可能要求你在工具条中增加类似文本框,单选框、选择面板,combobox等windows控件,今天有个同事问我这个问题就在这里做一个实例。供大家参考。

具体实现:

1 知识整备

(1 )其实要实现这个效果很简单,只要大家了解Arcgis中的IToolControl接口的使用方法,就不难实现。

IToolControl 这个接口有只有简单的三个方法:

 
hwnd:是个只读属性,用于给调用者返回控件 句柄。
OnDrop:是一个方法,用于调用者验证当前控件是否可拖动。
OnFocus:是一个方法,用于调用通知当前项,你已经聚焦。
(2)除了了解IToolCotrol接口之外,大家还必须具备知道如何创建Arcgis 命令插件的知识,以及如何调用插件的方法。
 
2 实现
   以一个简单Combobox为例:
    public sealed class Command1 : BaseCommand, IToolControl
    {

private int _handle = 0;
        private ICompletionNotify _CompNotify;
        private System.Windows.Forms.ComboBox comboBox = new System.Windows.Forms.ComboBox();
        private IHookHelper m_hookHelper = null;
        public Command1()
        {
            this._handle = comboBox.Handle.ToInt32();
            comboBox.Items.Add("大家好才是真的好1");
            comboBox.Items.Add("大家好才是真的好1");
            comboBox.Items.Add("大家好才是真的好1");
        }

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

// TODO:  Add other initialization code
        }

/// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            // TODO: Add Command1.OnClick implementation
        }

#endregion

#region IToolControl 成员

public bool OnDrop(esriCmdBarType barType)
        {
            if (barType == esriCmdBarType.esriCmdBarTypeToolbar)
            {
                return true;
            }
            else return false;
        }

public void OnFocus(ICompletionNotify complete)
        {
            _CompNotify = complete;
        }

public int hWnd
        {
            get
            {
                return _handle;
            }
        }

#endregion
    }

3 实现效果
 
照着这个实例可以添加,其它的windows控件
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.ADF.CATIDs;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.SystemUI; namespace AddCustomControlToToolbar
{
/// <summary>
/// Command that works in ArcMap/Map/PageLayout
/// </summary>
[Guid("7e8238b9-b38c-417c-894f-34ca9d99b634")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("AddCustomControlToToolbar.Command1")]
public sealed class Command1 : BaseCommand, IToolControl
{
#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 int _handle = ;
private ICompletionNotify _CompNotify;
private System.Windows.Forms.ComboBox comboBox = new System.Windows.Forms.ComboBox();
private IHookHelper m_hookHelper = null;
public Command1()
{
this._handle = comboBox.Handle.ToInt32();
comboBox.Items.Add("大家好才是真的好1");
comboBox.Items.Add("大家好才是真的好1");
comboBox.Items.Add("大家好才是真的好1");
} #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; // TODO: Add other initialization code
} /// <summary>
/// Occurs when this command is clicked
/// </summary>
public override void OnClick()
{
// TODO: Add Command1.OnClick implementation
} #endregion #region IToolControl 成员 public bool OnDrop(esriCmdBarType barType)
{
if (barType == esriCmdBarType.esriCmdBarTypeToolbar)
{
return true;
}
else return false;
} public void OnFocus(ICompletionNotify complete)
{
_CompNotify = complete;
} public int hWnd
{
get
{
return _handle;
}
} #endregion
}
}

向ArcGIS的ToolBarControl中添加任意的windows控件的方法的更多相关文章

  1. 向ArcGIS的ToolBarControl中添加任意的windows组建的方法[转]

    向ArcGIS的ToolBarControl中添加任意的windows组建的方法[转] Link: http://www.cnblogs.com/mymhj/archive/2012/10/12/27 ...

  2. android 给LinearLayout中添加一定数量的控件,并让着一定数量的控件从右到左移动,每隔若干秒停顿一下,最后一个view链接第一个view,然后继续移动循环往复,形成一个死循环简单动画效果

    主类:IndexAnimationLinearLayout.java package com.yw.sortlistview; import java.util.ArrayList; import j ...

  3. (转载)VC/MFC 工具栏上动态添加组合框等控件的方法

    引言 工具条作为大多数标准的Windows应用程序的 一个重要组成部分,使其成为促进人机界面友好的一个重要工具.通过工具条极大方便了用户对程序的操作,但是在由Microsoft Visual C++开 ...

  4. VC/MFC 工具栏上动态添加组合框等控件的方法

    引言 工具条作为大多数标准的Windows应用程序的一个重要组成部分,使其成为促进人机界面友好的一个重要工具.通过工具条极大方便了用户对程序的操作,但是在由Microsoft Visual C++开发 ...

  5. C#中缓存的使用 ajax请求基于restFul的WebApi(post、get、delete、put) 让 .NET 更方便的导入导出 Excel .net core api +swagger(一个简单的入门demo 使用codefirst+mysql) C# 位运算详解 c# 交错数组 c# 数组协变 C# 添加Excel表单控件(Form Controls) C#串口通信程序

    C#中缓存的使用   缓存的概念及优缺点在这里就不多做介绍,主要介绍一下使用的方法. 1.在ASP.NET中页面缓存的使用方法简单,只需要在aspx页的顶部加上一句声明即可:  <%@ Outp ...

  6. js如何实现动态的在表格中添加和删除行?(两种方法)

    js如何实现动态的在表格中添加和删除行?(两种方法) 一.总结 1.table元素有属性和一些方法(js使用) 方法一:添加可通过在table的innerHTML属性中添加tr和td来实现 tab.i ...

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

    Dixon 原文  用ArcGIS Engine.VS .NET和Windows控件开发GIS应用     此过程说明适合那些使用.NET建立和部署应用的开发者,它描述了使用ArcGIS控件建立和部署 ...

  8. ArcGIS ElementLayer上放置Windows控件

    ElementLayer是ArcGIS API for Silverlight/WPF中的一种图层类型,主要用来承载Silverlight/WPF中的UIElement对象(UIElement),使用 ...

  9. Android 可单选多选的任意层级树形控件

    花了几天研究了下鸿扬大神的博客<Android打造任意层级树形控件,考验你的数据结构和设计>,再结合公司项目改造改造,现在做个笔记. 先看看Demo的实现效果.首先看的是多选效果 再看看单 ...

随机推荐

  1. Spark入门实战系列--7.Spark Streaming(上)--实时流计算Spark Streaming原理介绍

    [注]该系列文章以及使用到安装包/测试数据 可以在<倾情大奉送--Spark入门实战系列>获取 .Spark Streaming简介 1.1 概述 Spark Streaming 是Spa ...

  2. 为什么需要Bundler

    对于从Node.js转Ruby的人很可能会有和我一样的疑惑,为什么要有Bundler这个东西?Rubygems不够吗? 从Node.js到Ruby的包管理器 在Node的世界里,依赖管理是由npm来完 ...

  3. ATL是如何实现线程安全的引用计数和多线程控制的

    ATL是如何实现线程安全的引用计数和多线程控制的 正如标题所示,这是我经常被问到的一个问题,而每次我都从头开始给人说一次,其实说来过程理解起来的确有点复杂. 我们的每一个ATL Server Obje ...

  4. 解决AndroidADT自带Eclipse编辑器不能自动代码提示的问题。

    今天发现,我下载的AndroidADT开发套装中自带的Eclipse没有自动代码提示功能.通过参考http://blog.csdn.net/coolszy/article/details/724195 ...

  5. C#多线程技术总结(同步)

    二.串行(同步): 1.lock.Monitor--注意锁定的对象必需是引用类型(string类型除外) 示例: private static object syncObject = new obje ...

  6. PHP--冒泡、选择、插入排序法

    使用php来实现常用三种排序方法: 冒泡.选择.插入中,最优的是插入排序,我就把插入排序的流程画下来了: 插入排序法的流程图: 插入排序的代码: function InsertSort(&$a ...

  7. Nancy FormsAuthentication使用

    1.新建UserDatabase类,实现IUserMapper接口 using System; using System.Collections.Generic; using System.Linq; ...

  8. 重写onStart()函数

    Android开发中有时会遇到这种情况,在数据列表的Activity中点击添加按钮,弹出另一个Activity添加数据,这样返回数据列表的Activity时就需要刷新数据列表(因为添加了一条数据).这 ...

  9. luogg_java学习_03_流程控制及循环结构

    本文为博主辛苦总结,希望自己以后返回来看的时候理解更深刻,也希望可以起到帮助初学者的作用. 转载请注明 出自 : luogg的博客园 谢谢配合! 程序流程控制 顺序结构 分支结构:if-else,sw ...

  10. java一点小的知识点

    1.在dos底下编译运行java文件时,若有包名,需要建立包名对应的文件夹,然后编译的时候写出包名:java.mypack.PackageDemo 2.代码中有包名的时候,自动创建文件夹并编译的方法: ...