Indicates if this command is enabled.
[Visual Basic 6.0] Property Enabled As Boolean
[Visual Basic .NET] Public ReadOnly Property Enabled As Boolean
[C#] public bool Enabled {get;}
[Java] public boolean isEnabled() throws IOException, AutomationException
[C++]
HRESULT get_Enabled(
VARIANT_BOOL* Enabled
);
Parameters
Enabled [out, retval]
Enabled is a parameter of type VARIANT_BOOL
When implementing ICommand to create a custom command, add some logic to the Enabled property to specify in what state the application should be in for the command to be enabled.
The following example makes the command enabled only when there is at least one data layer loaded in ArcMap.
private IApplication m_pApp; //ArcMap application
public bool Enabled()
{
//pApp is set in OnCreate
IMxDocument mxDoc = m_pApp.Document As IMxDocument;
int layerCount = pMxDoc.FocusMap.LayerCount;
if (pLayerCount > 0)
return true;
else
return false;
}
public void OnCreate(object hook)
{
// The hook argument is a pointer to Application object.
m_pApp = hook as IApplication;
}
The following example makes the command enabled only when there is at least one data layer loaded in ArcMap.
Dim m_pApp As IApplication 'ArcMap application
Private Property Get ICommand_Enabled() As Boolean
Dim pMxDoc As IMxDocument
Dim pLayerCount As Integer
'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 Property
Private Sub ICommand_OnCreate(ByVal hook As Object)
' The hook argument is a pointer to Application object.
Set m_pApp = hook
End Sub
The following example makes the command enabled only when there is at least one data layer loaded in ArcMap.
Private m_pApp As IApplication 'ArcMap application
Public ReadOnly Property Enabled() As Boolean Implements ESRI.ArcGIS.SystemUI.ICommand.Enabled
Dim mxDoc As IMxDocument
Dim layerCount As Integer
'pApp is set in OnCreate
mxDoc = CType(m_pApp.Document, IMxDocument)
layerCount = mxDoc.FocusMap.LayerCount
If pLayerCount> 0 Then
Return True
Else
Return False
End If
End Property
Public Sub OnCreate(ByVal hook As Object) Implements ESRI.ArcGIS.SystemUI.ICommand.OnCreate
' The hook argument is a pointer to Application object.
m_pApp = CType(hook, IApplication)
End Sub