Custom tool buttons

To present a user-defined command to users, use a custom tool button. When a custom tool button is clicked, its associated script is executed. Custom tool buttons can be placed directly on a custom toolbar or in the drop-down menu of another tool button.

Tool buttons are represented by ToolItem objects in the ArcPad object model. A ToolItem object is also a collection of ToolItem objects (buttons in a drop-down menu). Tool buttons are represented by either TOOLBUTTON or MENUITEM elements in ArcPad XML. If a tool button is placed directly on a custom toolbar, it's represented by a TOOLBUTTON element. If it's placed on the drop-down menu of another tool button, it's represented by a MENUITEM element.

Attributes

The following tool button attributes are set at design time in ArcPad Studio in the Tool Properties dialog box. They cannot be changed at run time (some attributes have corresponding properties that can be accessed and changed at run time). Attributes beginning with the letters "on" are used to specify the script to run when an event occurs. These attributes are set on the Events page of the Tool Properties dialog box. Attributes are written to the customization file (.apa or arcpad.apx) in ArcPad XML format.

Events

Tool buttons generate two types of events: the OnClick event and OnPointer events (OnPointerDown, OnPointerMove, and OnPointerUp). You can specify a script to run whenever one of these types of events occurs. That is, for a given tool button, you can either handle the OnClick event or one or more of the OnPointer events. The following tool button events are available:

Properties

Tool button properties can be read and set at run time via scripts. The following tool button properties are available:

Methods

Tool button methods can be called at run time via scripts. The following tool button methods are available:

Reference a tool button

You can reference any tool button on a toolbar that is currently loaded, regardless of whether or not the toolbar or tool button is visible. You reference a tool button via its name or index. The two options for referencing a tool button are described in this section.

Direct reference

Direct reference involves referencing a tool button via its name or index and the Toolbar object that contains the tool button. For example, to reference a tool button with the name "tlbtnStatistics" that is the third tool button on a toolbar with the name "tlbTools", see the following sample code:

VBScript

Dim objToolBar
Set objToolbar = Application.ToolBars("tlbTools")
Dim objToolButton
Set objToolButton = objToolbar.Item("tlbtnStatistics")

JScript

var objToolbar = Application.ToolBars("tlbTools");
var objToolButton = objToolbar.Item("tlbtnStatistics");

Python

objToolbar = Application.ToolBars("tlbTools")
objToolButton = objToolbar.Item("tlbtnStatistics")

Or the following code:

VBScript

Dim objToolBar
Set objToolbar = Application.ToolBars("tlbTools")
Dim objToolButton
Set objToolButton = objToolbar.Item(1)

JScript

var objToolbar = Application.ToolBars("tlbTools");
var objToolButton = objToolbar.Item(1);

Python

objToolbar = Application.ToolBars("tlbTools")
objToolButton = objToolbar.Item(1)

Tool buttons that are present in a drop-down menu (menu items) are referenced the same way as tool buttons without drop-down menus; however, use the item's name, not the index, because the index of items in a drop-down menu changes as items are promoted to the top of the menu. For example, to reference a tool button with the name "tlbtnOption2" that is on a drop-down menu, see the following sample code:

VBScript

Dim objToolBar
Set objToolbar = Application.ToolBars("tlbTools")
Dim objToolButton
Set objToolButton = objToolbar.Item("tlbtnOption2")

JScript

var objToolbar = Application.ToolBars("tlbTools");
var objToolButton = objToolbar.Item("tlbtnOption2");

Python

objToolbar = Application.ToolBars("tlbTools")
objToolButton = objToolbar.Item("tlbtnOption2")

Event reference

Event reference involves referencing a tool button in an event handling script. For example, to reference a tool button in its OnClick event handler, see the following sample code:

VBScript

Dim objToolButton
Set objToolButton = ThisEvent.Object

JScript

var objToolButton = ThisEvent.Object;

Python

objToolButton = ThisEvent.Object

Click a tool button

To click a tool button, reference the tool button and call its Click method. For example, to click a tool button named "tlbtnStatistics" on a toolbar named "tlbTools", see the following sample code:

VBScript

Application.ToolBars("tlbTools").Item("tlbtnStatistics").Click

JScript

Application.ToolBars("tlbTools").Item("tlbtnStatistics").Click();

Python

Application.ToolBars("tlbTools").Item("tlbtnStatistics").Click()

Enable or disable a tool button

To enable or disable a tool button, reference the tool button and set its Enabled property to true or false, respectively. For example, to enable a tool button named "tlbtnStatistics" on a toolbar named "tlbTools", see the following sample code:

VBScript

Application.ToolBars("tlbTools").Item("tlbtnStatistics").Enabled = True

JScript

Application.ToolBars("tlbTools").Item("tlbtnStatistics").Enabled = true;

Python

Application.ToolBars("tlbTools").Item("tlbtnStatistics").Enabled = True

To disable the same tool button, see the following sample code:

VBScript

Application.ToolBars("tlbTools").Item("tlbtnStatistics").Enabled = False

JScript

Application.ToolBars("tlbTools").Item("tlbtnStatistics").Enabled = false;

Python

Application.ToolBars("tlbTools").Item("tlbtnStatistics").Enabled = False

2/7/2013