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

IMapControl2.Layer Property (ArcObjects .NET 10.8 SDK)
ArcObjects Help for .NET developers > ArcObjects Help for .NET developers > ArcObjects namespaces > Controls > ESRI ArcGIS Controls > Interfaces > IM > IMapControl2 Interface > IMapControl2.Layer Property
ArcGIS Developer Help

IMapControl2.Layer Property

Layer at the supplied index.

[Visual Basic .NET]
Public Function get_Layer ( _
    ByVal index As Integer _
) As ILayer
public ILayer get_Layer (
    int index
HRESULT get_Layer(

Product Availability

Available with ArcGIS Engine.


The Layer property is a shortcut to IMap::Layer and is used to access a particular layer in the Map. The Layer at the beginning or top of the collection with an index of 0 will be drawn last, whilst the Layer at the bottom of the collection will be drawn first.


To loop through a Map's Layer collection use the Layer property in conjunction with the LayerCount property.


In C# use the get_Layer method, as indexed property accessors are not supported.

ILayer layer;
//First layer to draw
layer = (ILayer2) axMapControl1.get_Layer(0);
//Second layer to draw
layer = (ILayer2) axMapControl1.get_Layer(1);
//Last layer to draw
layer = (ILayer2) axMapControl1.get_Layer(axMapControl1.LayerCount - 1);

//Loop through a map's layer collection
ILayer layer;
for (int i=0; i<=axMapControl1.LayerCount-1; i++)
    layer = (ILayer) axMapControl1.get_Layer(i);
    //Do something...

[Visual Basic .NET]

The IMapControl2, (and higher numbered IMapControl interfaces) and IMapControlDefault interfaces have a default indexed property called Layer. The Controls interop assembly which provides access to these interfaces have the default Layer property. However, if you are working directly with the AxControls class use the get_Layer method.

Dim pLayer As ILayer
'First layer to draw
pLayer = AxMapControl1.get_Layer(0)
'Second layer to draw
pLayer = AxMapControl1.get_Layer(1)
'Last layer to draw
 pLayer = AxMapControl1.get_Layer(AxMapControl1.LayerCount - 1)

'Loop through a map's layer collection
Dim i As Long
Dim pLayer As ILayer
For i = 0 To AxMapControl1.LayerCount - 1
  pLayer = AxMapControl1.get_Layer(i)
  'Do something...
Next i

See Also

IMapControl2 Interface | IMapControl4.ClearLayers Method | IMapControl2.ClearLayers Method | IMapControl3.ClearLayers Method | IMapControl4.DeleteLayer Method | IMapControl2.DeleteLayer Method | IMapControl3.DeleteLayer Method | IMapControl4.LayerCount Property | IMapControl3.LayerCount Property | IMapControl2.LayerCount Property | IMapControl2.MoveLayerTo Method | IMapControl4.MoveLayerTo Method | IMapControl3.MoveLayerTo Method

.NET Samples

Geoevents in a MapControl