ArcGis 中MapControl 框选

void mCtrl_OnMouseDown( object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
        {
             #region 框选
            
            
            if (e.button == 4)
            {
                IEnvelope pEnvelope = mCtrl.TrackRectangle();  // 通过鼠标,取得一个包络线对象
                ISelectionEnvironment pSelectionEnv = new SelectionEnvironmentClass();  // 设置一个新环境
                pSelectionEnv.DefaultColor = MapHelper.GetRGBColor(Color.Red);     // 再改变原来要素的眼神值
                mCtrl.Map.SelectByShape(pEnvelope, pSelectionEnv, false);
                mCtrl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);

                ISelection selection = mCtrl.Map.FeatureSelection;
                IEnumFeatureSetup enumFeatureSetup = selection as IEnumFeatureSetup;    //这里很必要
                enumFeatureSetup.AllFields = true;                                      //这里很必要
                IEnumFeature enumFeature = enumFeatureSetup as IEnumFeature;
                enumFeature.Reset();
                IFeature feature = enumFeature.Next();

                IFeatureLayer pFeatureLayer = (IFeatureLayer)mCtrl.get_Layer(currentLayerIndex);
                IFeatureClass pFeatureClass = (IFeatureClass)pFeatureLayer.FeatureClass;

                int fLCDIdx = pFeatureClass.FindField(fieldName);
                lbFields.Items.Clear();
                while (feature != null)
                {
                    var _lcd = feature.get_Value(fLCDIdx);
                    long lcd = Convert.ToInt64(_lcd);
                    lbFields.Items.Add(lcd);
                    feature = enumFeature.Next();
                }
            }
            


             #endregion

            mCtrl.Refresh(esriViewDrawPhase.esriViewForeground, Type.Missing, Type.Missing);
        }

你可能感兴趣的:(arcgis)