1、使用IEnumFeature对象获取map中的FeatureSelection,该方法可以获取所有图层的选择要素
Dim m_pMap as Imap
Set m_pMap=Mapcontrol1.Map
Dim pEnumFeature As IEnumFeature
Set pEnumFeature = m_pMap.FeatureSelection
Dim pfeat As IFeature
Set pfeat = pEnumFeature.Next
Do while not pfeat is nothing
‘opera
Set pfeat=pEnumFeature.Next
Loop
2、使用ISelectionSet,IEnumIDs,FeatureClass.GetFeature()方法获取某个图层中的选择要素
Dim lyr2 As IFeatureLayer
Set lyr2 = MapControl1.Layer(1)
Dim selection As IFeatureSelection
Set selection = lyr2
Dim psel As ISelectionSet
Set psel = selection.SelectionSet
Dim lID As Long
Dim pEnumIDs As IEnumIDs
Set pEnumIDs = psel.IDs
Dim s As String
Dim pFeature As IFeature
lID = pEnumIDs.Next
Do
Set pFeature = lyr2.FeatureClass.GetFeature(lID)
‘opera
lID = pEnumIDs.Next
Loop Until lID = -1 \'-1 is returned after last valid ID has been reached