axToolbarControl1.AddItem的item为自定义工具时,VS提示命令无效,这是为什么
时间: 2023-12-06 18:42:05 浏览: 35
`AxToolbarControl` 控件是 ArcGIS Engine 中的一个工具条控件,用于在工具条上添加工具按钮。当你使用 `AddItem` 方法添加自定义工具时,需要指定该工具的 ID 和类型,以便 ArcGIS Engine 能够识别并加载该工具。如果你在添加工具时遇到了“命令无效”的提示,可能是以下原因导致的:
1. 未正确设置工具 ID:工具 ID 必须是唯一的,且只能由数字和字母组成。如果你的工具 ID 不符合要求,可能会导致 ArcGIS Engine 无法加载该工具。
2. 未正确设置工具类型:`AddItem` 方法需要指定工具的类型,例如 `esriCommandTypes.esriCmdTypeGeneric`、`esriCommandTypes.esriCmdTypeMapTool` 等。如果你未正确设置工具类型,可能会导致 ArcGIS Engine 无法识别该工具。
3. 工具未正确实现:如果你的自定义工具没有正确实现必要的接口和方法,例如 `ICommand` 接口和 `OnCreate` 方法,可能会导致工具无法被加载和运行。
你可以检查以上三个方面,看看是不是哪个方面出了问题,进而解决“命令无效”的问题。
相关问题
arcgis engine中如何定义用于axToolbarControl1.AddItem中添加的自定义工具对象
在 ArcGIS Engine 中定义用于 `axToolbarControl1.AddItem` 中添加的自定义工具对象,需要实现以下步骤:
1. 创建一个类,实现 ITool 接口。
```csharp
public class MyCustomTool : ESRI.ArcGIS.Framework.ITool {
// ...
}
```
2. 实现 ITool 接口中的方法,包括 OnCreate、OnClick、OnMouseDown 等事件处理方法。
```csharp
public void OnCreate(object hook){
// ...
}
public void OnClick(){
// ...
}
public void OnMouseDown(int Button, int Shift, int X, int Y){
// ...
}
```
3. 在 OnCreate 方法中创建工具栏按钮的图标,并将其赋值给 Bitmap 以供之后使用。
```csharp
public void OnCreate(object hook){
// ...
bitmap = new Bitmap(GetType().Assembly.GetManifestResourceStream("MyNamespace.MyCustomTool.png"));
}
```
4. 在 ITool 接口中实现 Name、Caption、Category、Bitmap、Enabled 属性,以及 Cursor 属性和 ToolTip 属性。
```csharp
public string Name{
get { return "MyCustomTool"; }
}
public string Caption{
get { return "My Custom Tool"; }
}
public string Category{
get { return "My Custom Category"; }
}
public Bitmap Bitmap{
get { return bitmap; }
}
public bool Enabled{
get { return true; }
}
public int Cursor{
get { return -1; }
}
public string ToolTip{
get { return "My Custom Tool"; }
}
```
5. 在窗体中的 `axToolbarControl1_OnCreate` 事件中添加自定义工具对象。
```csharp
private void axToolbarControl1_OnCreate(object sender, IToolbarControlEvents_OnCreateEvent e){
// ...
MyCustomTool myTool = new MyCustomTool();
axToolbarControl1.AddItem(myTool, -1, -1, false, -1, esriCommandStyles.esriCommandStyleIconAndText);
}
```
这样就可以在工具栏中添加自定义工具对象了。
axToolbarControl1.AddItem的六个参数是什么
axToolbarControl1.AddItem 是 ArcGIS Engine 中的一个方法,用于向工具栏中添加一个新的按钮或者工具。
axToolbarControl1.AddItem 方法的六个参数分别是:
1. item:要添加的工具或按钮对象,可以是 ICommand 接口的一个实例,也可以是一个自定义的工具类对象。
2. index:要添加的工具或按钮在工具栏中的位置,从 0 开始计数。
3. group:工具或按钮所属的分组名称,可以为 null。
4. subType:工具或按钮的 subtype 值,用于标识工具或按钮的类型。
5. bitmap:工具或按钮的图标,可以为 null。
6. caption:工具或按钮的文本提示。
其中,前三个参数是必需的,后三个参数可以为 null。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)