This document is archived and information here might be outdated.  Recommended version.


ICommand.Enabled Property (ArcObjects .NET 10.8 SDK)
ArcObjects Help for .NET developers > ArcObjects Help for .NET developers > ArcObjects namespaces > SystemUI > ESRI.ArcGIS.SystemUI > Interfaces > IC > ICommand Interface > ICommand.Enabled Property
ArcGIS Developer Help

ICommand.Enabled Property

Indicates if this command is enabled.

[Visual Basic .NET]
Public ReadOnly Property Enabled As Boolean
[C#]
public bool Enabled {get;}
[C++]
HRESULT get_Enabled(
  Boolean* Enabled
);
[C++]
Parameters
Enabled [out, retval]

Enabled is a parameter of type bool*

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Remarks

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.   

[C#]

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;
 }

[Visual Basic .NET]

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

See Also

ICommand Interface