概要:在使用ArcEngine开发中,给ToolbarControl添加按钮形式的命令项相信大家都很熟悉了,因为网上的例子很多。但这种使用click调用功能的方式只能满足大部分用户在体验方面的需求,除此之外用户很可能要求你在工具条中增加类似文本框,单选框、选择面板,combobox等windows控件,今天有个同事问我这个问题就在这里做一个实例。供大家参考。
具体实现:
1 知识整备
(1 )其实要实现这个效果很简单,只要大家了解Arcgis中的IToolControl接口的使用方法,就不难实现。
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
}