This document is archived and information here might be outdated. Recommended version. |
ArcObjects namespaces > Controls > ESRI ArcGIS Controls > Interfaces > IM > IMapControlDefault Interface > IMapControlDefault.AddLayerFromFile Method (ArcObjects .NET 10.4 SDK) |
Loads a layer file and adds it to the Map's collection of layers at the specified index position.
[Visual Basic .NET] Public Sub AddLayerFromFile ( _ ByVal lyrPath As String, _ [ByVal toIndex As Integer] _ )
[C#] public void AddLayerFromFile ( string lyrPath, int toIndex );
Optional Values
[C++]
HRESULT AddLayerFromFile(
BSTR lyrPath,
long toIndex
);
[C++]
Parameters lyrPath [in] lyrPath is a parameter of type BSTR toIndex [in, optional, defaultvalue(0)] toIndex is a parameter of type long
When a layer file is added to the MapControl's layer collection and no index is specified, it is added to the beginning or top of the collection with an index of 0. The numeric index of any other layers in the layer collection increments by one.
When a layer file is added and an index is specified, the numeric index of any other layers in the layer collection will increment by one, except for those layers with an index less than the specified index. The index of these layers will remain the same.
1023 800a03ff: The specified index is out of range
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.
Use the MoveLayerTo method to change the position of a Layer within the layer collection.
//Add layer at index 0 axMapControl1.AddLayerFromFile(@"C:\Temp\myLayer.lyr",0); //Add layer at index 2 axMapControl1.AddLayerFromFile(@"C:\Temp\myLayer.lyr", 2);
'Add layer at index 0 AxMapControl1.AddLayerFromFile("C:\Temp\myLayer.lyr") 'Add layer at index 2 AxMapControl1.AddLayerFromFile("C:\Temp\myLayer.lyr", 2)
IMapControlDefault Interface | IMapControl4.AddLayer Method | IMapControlDefault.AddLayer Method | IMapControl3.AddLayer Method | IMapControl3.AddShapeFile Method | IMapControlDefault.AddShapeFile Method | IMapControl4.AddShapeFile Method