📄 drawtext.frm
字号:
VERSION 5.00
Object = "{9BD6A640-CE75-11D1-AF04-204C4F4F5020}#2.0#0"; "mo20.ocx"
Begin VB.Form Form1
Caption = "DrawShape方法和DrawText方法示例"
ClientHeight = 4860
ClientLeft = 1935
ClientTop = 1485
ClientWidth = 6900
BeginProperty Font
Name = "Terminal"
Size = 6
Charset = 255
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
LinkTopic = "Form1"
PaletteMode = 1 'UseZOrder
ScaleHeight = 4860
ScaleWidth = 6900
Begin VB.CommandButton Command2
Caption = "全图显示"
BeginProperty Font
Name = "宋体"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 5520
TabIndex = 2
Top = 1320
Width = 1215
End
Begin VB.CommandButton Command1
Caption = "重置"
BeginProperty Font
Name = "宋体"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 5520
TabIndex = 1
Top = 720
Width = 1215
End
Begin VB.TextBox Text1
BeginProperty Font
Name = "Times New Roman"
Size = 15.75
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 120
TabIndex = 0
Text = "输入文字..."
Top = 4200
Width = 5295
End
Begin MapObjects2.Map Map1
Height = 3975
Left = 120
TabIndex = 3
Top = 120
Width = 5295
_Version = 131072
_ExtentX = 9340
_ExtentY = 7011
_StockProps = 225
BackColor = 16777215
BorderStyle = 1
Contents = "DrawText.frx":0000
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim g_line As MapObjects2.Line
Dim pts As MapObjects2.Points
Dim tHeight As Double
'"重置"按钮单击响应事件
Private Sub Command1_Click()
'清空之前生成的几何图形
Set g_line = Nothing
Set pts = Nothing
Map1.TrackingLayer.Refresh True
End Sub
'"全图显示"按钮单击响应事件
Private Sub Command2_Click()
Map1.Extent = Map1.FullExtent
End Sub
Private Sub Form_Load()
'连接地理数据库
'这里是MapObjects自带的World数据
'默认路径在C:\Program Files\ESRI\MapObjects2\Samples\Data\World
Dim dc As New DataConnection
dc.Database = "C:\Program Files\ESRI\MapObjects2\Samples\Data\World"
If Not dc.Connect Then End
'读入country图层
Dim layer As New MapLayer
Set layer.GeoDataset = dc.FindGeoDataset("country")
layer.Symbol.Color = moPaleYellow
Map1.Layers.Add layer
tHeight = Map1.Extent.Height / 8
End Sub
Private Sub Map1_AfterTrackingLayerDraw(ByVal hDC As StdOle.OLE_HANDLE)
'确定g_line是不是空
If Not g_line Is Nothing Then
'确认g_line有至少两个顶点
If pts.Count > 1 Then
Dim tSym As New TextSymbol
'使用TextBox的字体
Set tSym.Font = Text1.Font
Dim sym As New Symbol
sym.Color = moRed
'使用DrawShape方法在Map Control中使用sym符号显示g_line图形
Map1.DrawShape g_line, sym
tSym.Height = tHeight
'使用DrawText方法在Map Control中使用tSym符号显示Text1中的文字
Map1.DrawText Text1.Text, g_line, tSym
End If
End If
End Sub
Private Sub Map1_MouseDown(Button As Integer, Shift As Integer, _
x As Single, y As Single)
If Button = 1 Then
'鼠标左键被单击
'当线段对象不存在时建立Line对象
If g_line Is Nothing Then
Set g_line = New MapObjects2.Line
End If
'建立Points对象
If pts Is Nothing Then
Set pts = New MapObjects2.Points
End If
'建立Point对象,并将其添加到Line对象
Dim p As Point
Set p = Map1.ToMapPoint(x, y)
pts.Add p
If pts.Count = 1 Then
g_line.Parts.Add pts
Set pts = g_line.Parts(0)
End If
'刷新TrackingLayer层
Map1.TrackingLayer.Refresh True
Else
'鼠标右键被单击
'放大地图
Dim r As MapObjects2.Rectangle
Set r = Map1.TrackRectangle
If Not r Is Nothing Then Map1.Extent = r
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -