ArcEngine中ToolBarControl集成到c#的toolstrip中

方法1:直接把esri控件添加到toolstrip中
toolStrip.Items.Add(new ToolStripControlHost(axToolbarControl1));

方法2:使用ITool把toolstrip的按钮和命令关联
private void addToolbarcontrolBT()
{
      //添加zoomin
        ToolStripButton tsb = new ToolStripButton();
                tsb.Name = "zoomin";
                tsb.Image = new Bitmap(@"E:\zoomin.jpg");
                tsb.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
                tsb.Click += new System.EventHandler(Menu_Click);
                MF_ToolStrip.Items.Add(tsb);

    //添加fullextent
               tsb = new ToolStripButton();
                tsb.Name = "fullextent";
                tsb.Image = new Bitmap(@"E:\fullextent.jpg");
                tsb.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
                tsb.Click += new System.EventHandler(Menu_Click);
                MF_ToolStrip.Items.Add(tsb);
}

private void Menu_Click(object sender, EventArgs e)
{
            string itemName = ((ToolStripItem)sender).Name;
            ICommand pCommand = null;
            if (itemName == "zoomin")
            {
                pCommand = new ESRI.ArcGIS.Controls.ControlsMapZoomInToolClass();
                //创建ICommand接口的OnCreate创建关联Mapcontrol
                pCommand.OnCreate(this.axMapControl1.Object);
                //QI至ITool
                ITool pTool = pCommand as ITool;
                //指定当前工具
                this.axMapControl1.CurrentTool = pTool;
            }
            else if (itemName == "fullextent")
            {
                                pCommand = new ESRI.ArcGIS.Controls.ControlsMapFullExtentCommandClass();
                pCommand.OnCreate(this.axMapControl1.Object);
                pCommand.OnClick();
               
            }
            else
            {
                return;
            }
}

你可能感兴趣的:(ArcEngine)