private void axTOCControl1_ (  sender, ITOCControlEvents_ Event e)
                {
                    esriTOCControlItem item = esriTOCControlItem.esriTOCControlItemNone;
                    IBasicMap map = null;     = null;
                      other = null;   index = null;
                    this.axTOCControl1.HitTest(e.x, e.y, ref item, ref map, ref  , ref other, ref index);

                    if (e.button == 2)
                    {
                        IFeature  feature ;
                        feature  =   as IFeature ;
                        //IFeature  feature  = axMapControl1.get_ (6) as IFeature ;
                         Fields  Fields = feature  as  Fields;
                        List<string> list = new List<string>();

                        for (int i = 0; i < axMapControl1.Map. Count; i++)
                        {
                            string  _name = axMapControl1.Map.get_ (i).Name.ToString();
                            list.Add( _name);
                        }

                        for (int i = 0; i <  Fields.FieldCount; i++)
                        {
                            IField field =  Fields.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. Count)
                            {
                                sum += tucengming + list[j].ToString() + \"  \";

                            }
                            else
                            {
                                string ziduanming = \"字段名:\";
                                sum += ziduanming + list[j].ToString() + \"  \";
                            }

                        }

                        MessageBox.Show(sum, \"图层名和字段名\");
                    }
                }

运行效果:

\"\"

收藏 打印