[Visual Basic 6.0]This example shows how to create a custom command, MyCommand, using Visual Basic.
When you click on this command, a message box is displayed. This command is enabled only when there is at least one data layer loaded in ArcMap.To use this example:
- Create a new ActiveX dll Visual Basic project. In the VB project, add reference to ESRI SystemUI Library (esriSystemUI.olb), ESRI Framework Library (esriFramework.olb), ESRI ArcMapUI Library (esriArcMapUI.olb)
- Paste this code into a class module.
- Add a form called Form1 and put a PictureBox control called Picture1 on the form.
- Then set the Picture property of Picture1 to a bitmap that you want to use for the bitmap for the command.
- Compile the project to create the dll.
- In the Customize dialog in ArcMap, click Add from file and navigate to the dll you just created. The custom command will be added to ArcMap.
- In the Commands panel of the Customize dialog, select MyCustomTools in the Categories list.
- In the Commands list, select MyCommand and drag it to a toolbar.
- Test the command.Option Explicit
' Implement the ICommand interface
Implements ICommandDim m_pApp As IApplication 'ArcMap application
Private Property Get ICommand_Bitmap() As esriSystem.OLE_HANDLE
' The VB project contains a form called Form1.
' Picture1 is the name of a PictureBox control on the form.
' The Picture property of PictureBox1 is set to some bitmap on
' your system.
ICommand_Bitmap = Form1.Picture1.Picture.Handle
End PropertyPrivate Property Get ICommand_Caption() As String
' Set the string that appears when the command is used as a
' menu item.
ICommand_Caption = "MyCommand"
End PropertyPrivate Property Get ICommand_Category() As String
' Set the category of this command. This determines where the
' command appears in the Commands panel of the Customize dialog.
ICommand_Category = "MyCustomTools"
End PropertyPrivate Property Get ICommand_Checked() As Boolean
End Property
Private Property Get ICommand_Enabled() As Boolean
' Add some logic here to specify in what state the application
' should be in for the command to be enabled. In this example,
' the command is enabled only when there is at least one data
' layer loaded in ArcMap.
Dim pMxDoc As IMxDocument
Dim pLayerCount As Integer
'm_pApp is set in OnCreate
Set pMxDoc = m_pApp.Document
pLayerCount = pMxDoc.FocusMap.LayerCount
If pLayerCount > 0 Then
ICommand_Enabled = True
Else
ICommand_Enabled = False
End If
End PropertyPrivate Property Get ICommand_HelpContextID() As Long
ICommand_HelpContextID = 1234
End PropertyPrivate Property Get ICommand_HelpFile() As String
' If the help file is not registered you may need
' to supply the full path to the file
ICommand_HelpFile = "MyHelp.hlp"
End PropertyPrivate Property Get ICommand_Message() As String
'Set the message string that appears in the statusbar of the
'application when the mouse passes over the command.
ICommand_Message = "This is my custom command"
End PropertyPrivate Property Get ICommand_Name() As String
' Set the internal name of this command. By convention, this
' name string contains the category and caption of the command.
ICommand_Name = "MyCustomTool_MyCommand"
End PropertyPrivate Sub ICommand_OnClick()
' Add some code to do some action when the command is clicked. In this
' example, a message box is displayed.
MsgBox "Clicked on my command"
End SubPrivate Sub ICommand_OnCreate(ByVal hook As Object)
' The hook argument is a pointer to Application object.
' Establish a hook to the application
Set m_pApp = hook
End SubPrivate Property Get ICommand_Tooltip() As String
'Set the string that appears in the screen tip.
ICommand_Tooltip = "MyCommand"
End Property
[Visual Basic .NET, C#, C++]
No example is available for Visual Basic .NET, C#, or C++. To view a Visual Basic 6.0 example, click the Language Filter button
in the upper-left corner of the page.