ToolbarControl resolve the ArcEngine

      ToolbarControlClass There are three main interfaces: 

 IToolbarControl, IToolbarControl2, IToolbarControlDefault  

     Which, IToolbarControl2 is a new version of IToolbarControl while IToolbarControlDefault is a 'pure' dispatch interface, the latest version is always IToolbarControl, that is, if they have IToolbarControl3, then IToolbarControlDefault is IToolbarControl3.

     There are three in IToolbarControlDefault Members can add items to ToolbarControl:

     AddItem () : Add an item to ToolbarControl, support the achievement of the ICommand, IMenuDef, IToolbarMenu, ITool, IToolControl, IPaletteDef and IToolbarPalette class.             

     AddMenuItem () : ToolbarControl to add a menu item, a brief AddItem (shear) version, support the achievement of the IMenuDef, IToolbarMenu class

     AddToolbarDef () : add custom tools to the item ToolbarControl.

Below AddItem example:

The first parameter is the type of object, it may be substantially: UID, ProgID, an interface (ICommand, IToolBarDef ...), e.g.

//Adding a command by UID
UID uID
= new UIDClass();
uID.Value
= "esriControls.ControlsMapFullExtentCommand";
axToolbarControl1.AddItem(uID,
-1,-1,false,0,esriCommandStyles.esriCommandStyleIconOnly);

//Adding a command by ProgID
string progID = "esriControls.ControlsMapFullExtentCommand";
axToolbarControl1.AddItem(progID,
-1,-1,false,0,esriCommandStyles.esriCommandStyleIconOnly);

//Adding a command by ICommand
ICommand command
= new ControlsMapFullExtentCommandClass();
axToolbarControl1.AddItem(command,
-1,-1,false,0,esriCommandStyles.esriCommandStyleIconOnly);

 

      ToolbarControl has an internal CommandPool, Command used to store management. When added to an ToolbarControl in time, the AddItem CommandPool check whether the Command already exists. If not, this is Created Command, and added CommandPool, using this count Command is set to 1. If the Command already exists, it is reused, the use count is incremented.

     Note ESRI.ArcGIS.Controls built-in Controls. ControlsMapZoomInFixedCommandClass like this to CommandClass ending generally implements ICommand interface. This Command will permanently need ITool MapControl interact with the interface, such as ControlsMapZoomInToolClass to ToolClass ends are achieved ITool class .ControlsFeatureSelectionToolbarClass that implements IToolBarDef interface classes that implement the various interfaces in use are different:

ICommand command = new ControlsOpenDocCommandClass();
command.OnCreate(m_mapControl.Object);
command.OnClick();

ICommand pCommand
= new ESRI.ArcGIS.Controls.ControlsMapZoomInToolClass();
pCommand.OnCreate(axMapControl1.Object);
axMapControl1.CurrentTool
= pCommand as ITool;

 

In ArcEngine you can choose how to use the tool bar:

 

1. Use of ArcEngine ToolbarControl, add an existing Command Controls using the Add function.

2. Use of ArcEngine ToolbarControl, add Command Controls own implementation of a function using the Add course Inherited from ICommand or ITool (or BaseCommand BaseTool or abstract class)

3. To achieve IToolBarDef interface to create custom toolbar (Tool Bar)

4. Use ControlsXXXXXXClass button, menu item or toolbar in general

<The above is purely personal understanding, if wrong, please leave a message, thank you>

Reproduced in: https: //www.cnblogs.com/LoveLyre/archive/2011/08/31/2160640.html

Guess you like

Origin blog.csdn.net/weixin_34066347/article/details/92840894