如何创建定制的工具条(Tool Bar)
本例要实现的是如何创建定制的工具条(Tool Bar)。就必须在类模块中实现IToolBarDef接口。IToolBarDef接口包括 Caption、ItemCount及Name三个属性和GetItemInfo方法。
l 要点
通过在类模块中实现IToolBarDef接口。IToolBarDef接口包括 Caption、ItemCount及Name三个属性和GetItemInfo方法。
·ItemCount属性表示ToolBar显示的条目(Button、Tool或其它控件)数。
· GetItemInfo方法定义工具条上各条目的CLSID,其中,参数pos表示条目在ToolBar中的位置,itemDef 是定义相应位置的条目的IItemDef 对象。
·工具条条目的CLSID分为两种:
1、系统CLSID,代表ArcGIS的一个功能,其引用方式为"esriCore.命令名称",如"esriCore.AddDataCommand"、"esriCore.FileSaveCommand"等。
2、用户定制CLSID,表示用户自己定义的功能。其引用方式为"工程名称.定制功能类名称",如" ToolBarDef.ClsBar "。必须注意,这里“定制功能类名称”是工程中实现的一个功能类名称,“工程名称”即为当前工程的名称(不是DLL文件名,也不是工具条的名称),每次新建一个工程时,系统默认的工程名在某些情况下无法使用(在中文版的VB中是一个乱字符),必须改名后方能用。
l 程序说明
程序在类模块中实现IToolBarDef接口来创建自己的工具条(ToolBar)。
l 代码
|
Option Explicit Implements IToolBarDef
Private Property Get IToolBarDef_Caption() As String IToolBarDef_Caption = "CustomToolBar" End Property
Private Sub IToolBarDef_GetItemInfo(ByVal pos As Long, ByVal itemDef As_ esriCore.IItemDef) '这里假设在当前工程(工程名称为ToolBarDef)中定义了一个类模块(名为ClsBar), '它实现了Icommand接口(可参照1.2.1) Select Case pos Case 0 '用户自定义条目 itemDef.ID = "ToolBarDef.ClsBar" itemDef.Group = False Case 1 '系统条目 itemDef.ID = "esriCore.AddDataCommand" itemDef.Group = False End Select End Sub
Private Property Get IToolBarDef_ItemCount() As Long IToolBarDef_ItemCount = 2
End Property
Private Property Get IToolBarDef_Name() As String IToolBarDef_Name = "CustomToolBar"
End Property |