ARCEngine中右鍵圖層以遍歷圖層名和欄位名
阿新 • • 發佈:2019-01-02
private void axTOCControl1_OnMouseDown(object sender, ITOCControlEvents_OnMouseDownEvent e) { esriTOCControlItem item = esriTOCControlItem.esriTOCControlItemNone; IBasicMap map = null; ILayer layer = null; object other = null; object index = null; this.axTOCControl1.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index); if (e.button == 2) { IFeatureLayer featureLayer; featureLayer = layer as IFeatureLayer; //IFeatureLayer featureLayer = axMapControl1.get_Layer(6) as IFeatureLayer; ILayerFields layerFields = featureLayer as ILayerFields; List<string> list = new List<string>(); for (int i = 0; i < axMapControl1.Map.LayerCount; i++) { string layer_name = axMapControl1.Map.get_Layer(i).Name.ToString(); list.Add(layer_name); } for (int i = 0; i < layerFields.FieldCount; i++) { IField field = layerFields.get_Field(i); string fieldName = field.Name; list.Add(fieldName); } string sum = ""; for (int j = 0; j < list.Count; j++) { string tucengming = "圖層名:"; if (j < axMapControl1.Map.LayerCount) { sum += tucengming + list[j].ToString() + " "; } else { string ziduanming = "欄位名:"; sum += ziduanming + list[j].ToString() + " "; } } MessageBox.Show(sum, "圖層名和欄位名"); } }