现在的位置: 首页 > 综合 > 正文

自定义的工具栏中使用engine提供的内建命令

2013年08月31日 ⁄ 综合 ⁄ 共 1406字 ⁄ 字号 评论关闭
 感谢kisssy!!

代码如下  

private void Form1_Load(object sender, System.EventArgs e)
  {
   ToolbarControlClass axToolbarControl1 = new ToolbarControlClass();
   IToolbarControl toolBar1;
   toolBar1 = axToolbarControl1;
   toolBar1.SetBuddyControl(axMapControl1);
  
  }
  private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
  {
  
   if (e.Button == toolBarButton1)
   {
    ICommand command = new ControlsMapPanToolClass();
    command.OnCreate(axMapControl1.Object);
    axMapControl1.CurrentTool = command as ITool;
      }

   if (e.Button == toolBarButton2)
   {
    ICommand command = new ControlsMapFullExtentCommandClass();
    command.OnCreate(axMapControl1.Object);
    axMapControl1.CurrentTool = command as ITool;
     }
现在只有button1可用,button2不行,不知是何原因,请指教,谢谢

 

 

当然不行啊!

要注意Tool和Command的区别

通俗的说:

Command是在工具栏一点击,就出效果。如FullExtent,Refresh;

而Tool在工具栏点击后并无直接反映,而是等到你在地图上点击或移动后,产生效果,如Zoomin,Zoomout,Pan,Identify等等

具体哪些是Tool,哪些是Command,可以参照相关OMD。

Tool使用类似你的Button1;

而Command应该:

if (e.Button == toolBarButton2)
   {
    ICommand command = new ControlsMapFullExtentCommandClass();
    command.OnCreate(axMapControl1.Object);
    command.OnClick();
     }

 

commandpool:说白了就是Command Collection

hookhelper:一般在你自己写一个Command类模块的时候用,用法可以看例子,概括的讲:

1、Class_Initialize中:Set m_pHookHelper = New HookHelper
2、ICommand_OnCreate(ByVal hook As Object)中:Set m_pHookHelper.hook = hook
3、ICommand_OnClick()中就可以通过m_pHookHelper得到:ActiveViewFocusMapPageLayout(如在OnCreate中传入PageLayoutControl)。

抱歉!评论已关闭.