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


IMapControl4.Layer Property (ArcObjects .NET 10.6 SDK)
ArcObjects Library Reference (Controls)  

IMapControl4.Layer Property

Layer at the supplied index.

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

Product Availability

Available with ArcGIS Engine.

Description

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.

Remarks

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

[C#]

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);
    System.Windows.Forms.MessageBox.Show(layer.Name);
    //Do something...
}

[Visual Basic .NET]

The IMapControl4, (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

IMapControl4 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