1. 程式人生 > >根據圖層名獲取圖層和圖層序號

根據圖層名獲取圖層和圖層序號

很普遍的一個函式,留作備用,以後懶得寫了

     //根據圖層名獲取圖層
        private ILayer PRV_GetLayersByName(string IN_Name)
        {
            IEnumLayer Temp_AllLayer=axMapControl.Map.Layers;
            ILayer Each_Layer = Temp_AllLayer.Next();
            while (Each_Layer != null)
            {
                if (Each_Layer.Name.Contains(IN_Name))
                    return Each_Layer;
                Each_Layer = Temp_AllLayer.Next();
            }
            return null;
        }


        //根據圖層名獲取圖層序號
        private int PRV_GetIndexOfLayer(string IN_LayerName)
        {
           for (int i = 0; i < axMapControl.LayerCount; i++)
           {
               if (axMapControl.get_Layer(i).Name == IN_LayerName)
                   return i;
           }
           return -1;
        }