📄 form1.frm
字号:
VERSION 5.00
Object = "{9BD6A640-CE75-11D1-AF04-204C4F4F5020}#2.0#0"; "mo20.ocx"
Begin VB.Form Form1
Caption = "Field对象示例"
ClientHeight = 4575
ClientLeft = 60
ClientTop = 450
ClientWidth = 7545
LinkTopic = "Form1"
ScaleHeight = 4575
ScaleWidth = 7545
StartUpPosition = 3 '窗口缺省
Begin VB.ListBox List1
Height = 2940
Left = 5520
TabIndex = 4
Top = 1440
Width = 1935
End
Begin VB.ComboBox Combo1
Height = 300
Left = 5520
Style = 2 'Dropdown List
TabIndex = 2
Top = 600
Width = 1935
End
Begin MapObjects2.Map Map1
Height = 4335
Left = 120
TabIndex = 0
Top = 120
Width = 5295
_Version = 131072
_ExtentX = 9340
_ExtentY = 7646
_StockProps = 225
BackColor = 16777215
BorderStyle = 1
Contents = "Form1.frx":0000
End
Begin VB.Label Label2
Caption = "地图中相应字段的值:"
Height = 255
Left = 5520
TabIndex = 3
Top = 1080
Width = 1935
End
Begin VB.Label Label1
Caption = "字段:"
Height = 255
Left = 5520
TabIndex = 1
Top = 240
Width = 1215
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'组合框鼠标单击事件响应代码
Private Sub Combo1_Click()
'在List1中显示当前选择字段的值
Dim RecordsetX As MapObjects2.Recordset
Set RecordsetX = Map1.Layers(0).Records
List1.Clear
'循环获取Recordset中所有记录
Do Until RecordsetX.EOF
'获取字段值
List1.AddItem RecordsetX.Fields.Item(Combo1.Text).ValueAsString
'将数据游标向下移动
RecordsetX.MoveNext
Loop
End Sub
Private Sub Form_Load()
Call SetupLayers
Call GetFields
End Sub
Sub SetupLayers()
'调入数据
Dim dc As New DataConnection
'MapObjects自带的World地图
'默认路径为C:\Program Files\ESRI\MapObjects2\Samples\Data\World
dc.Database = "C:\Program Files\ESRI\MapObjects2\Samples\Data\World"
'若连接地理数据库失败,则结束程序
If Not dc.Connect Then End
'调入图层Country.shp
Dim layer As New MapLayer
Set layer.GeoDataset = dc.FindGeoDataset("Country")
Map1.Layers.Add layer
End Sub
Sub GetFields()
'获取MapLayer的Recordset对象中所有字段
'获取Country图层
Dim LayerX As MapLayer
Set LayerX = Map1.Layers(0)
'获取其数据集
Dim RecordsetX As MapObjects2.Recordset
Set RecordsetX = LayerX.Records
Combo1.Clear
'获取其中所有字段
Dim FieldX As MapObjects2.Field
For Each FieldX In RecordsetX.Fields
Combo1.AddItem FieldX.Name
Next
If Combo1.ListCount > 0 Then
Combo1.ListIndex = 0
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -