模仿ArcEngine的 Identify功能展示要素的属性信息

 1、先在主窗体中添加一个“详细信息按钮”,双击这个按钮添加如下事件:

 这个pMouseOperate是用来过滤在mapControl中的点击事件。

2、设计详细信息窗体,并对窗体中控件的属性用代码赋值并绑定

 

 public void showDetails(IFeature pFeature)
        {
            pfeature = pFeature;
            ArrayList arrlist = new ArrayList();
            for (int i = 0; i < pFeature.Fields.FieldCount; i++)
            {
                arrlist.Add(pFeature.get_Value(i));
            }
            //基本信息
            name = labelname2.Text = arrlist[4].ToString();
            IdNo = labelNO2.Text = arrlist[2].ToString();
            jhrNo = labeljhr2.Text = arrlist[3].ToString();
            sex = labelsex2.Text = arrlist[5].ToString();
            birthday = labelbirthady2.Text = arrlist[7].ToString();
            adress = textBoxadress1.Text = arrlist[14].ToString();
            //残疾情况
            cjtype = labelcjtype2.Text = arrlist[8].ToString();
            cjcause = labelcjcause2.Text = arrlist[9].ToString();
            cjdescription = textBoxcjdescription1.Text = arrlist[10].ToString();
            //康复情况
            kfdate = labelkfdata2.Text = arrlist[12].ToString();
            kforganization = labelkforganization3.Text = arrlist[11].ToString();
            kfdescription = textBoxkfdescription1.Text = arrlist[13].ToString();
            //照片
            ChildPicAddress = arrlist[15].ToString();
            JhrPicAddress = arrlist[16].ToString();

            //照片
            if (arrlist[15].ToString() == “”)
            {
                pictureBox1.Image = Image.FromFile(@”D:\ZHCL\ZHCL\module\errorpicture\error1.png”);
            }
            if (arrlist[16].ToString() == “”)
            {
                pictureBox2.Image = Image.FromFile(@”D:\ZHCL\ZHCL\module\errorpicture\error1.png”);
            }
            if(arrlist[15].ToString()!=””||arrlist[16].ToString()!=””)
            {
                try
                {
                    pictureBox1.Image = Image.FromFile(arrlist[15].ToString());
                    pictureBox2.Image = Image.FromFile(arrlist[16].ToString());
                }
                catch (Exception ex)
                {
                    MessageBox.Show(“照片路径不正确!”);
                }
            }
        }

3、在MapControl的点击事件中添加:

 if (pMouseOperate == “detail”)
            {
                IMap pMap = axMapControl1.Map;
                
                IActiveView pActiveView = pMap as IActiveView;
                IGeometry pGeometry = null;
                IEnvelope pEnv;
                pEnv = axMapControl1.TrackRectangle();
                if (pEnv.IsEmpty == true)//点选
                {
                    tagRECT r;
                    r.bottom = e.y + 30;
                    r.top = e.y – 30;
                    r.left = e.x – 30;
                    r.right = e.x + 30;
                    pActiveView.ScreenDisplay.DisplayTransformation.TransformRect(pEnv, ref r,4);
                    pEnv.SpatialReference = pActiveView.FocusMap.SpatialReference;
                }
                pGeometry = pEnv as IGeometry;
                axMapControl1.Map.SelectByShape(pGeometry, null, false);              
                pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);

 

                FormDetail frmdetail1 = new FormDetail();
                frmdetail1._CurMap = pMap;
                IEnumFeature pEnumFeature = pMap.FeatureSelection as IEnumFeature;
                IFeature pFeature = pEnumFeature.Next();
                
                
                if (pFeature != null)
                {
                    frmdetail1.showDetails(pFeature);
                }

                frmdetail1.Show();

            }

最终效果如图所示,测试用的,信息均是瞎填,儿童近照和监护人照片来源于网络,侵删。

转载自:https://blog.csdn.net/the_snail/article/details/82285064

You may also like...