📄 form1.frm
字号:
VERSION 5.00
Object = "{370A8DDA-7915-42DC-B4A1-77662C82B046}#1.0#0"; "TOCControl.ocx"
Object = "{B7D43581-3CBC-11D6-AA09-00104BB6FC1C}#1.0#0"; "ToolbarControl.ocx"
Object = "{C552EA90-6FBB-11D5-A9C1-00104BB6FC1C}#1.0#0"; "MapControl.ocx"
Object = "{BA01FAC9-2AB7-4CC9-9732-938340408ACE}#1.0#0"; "PageLayoutControl.ocx"
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 7830
ClientLeft = 60
ClientTop = 345
ClientWidth = 10185
LinkTopic = "Form1"
ScaleHeight = 7830
ScaleWidth = 10185
StartUpPosition = 3 '窗口缺省
Begin esriPageLayoutControl.PageLayoutControl PageLayoutControl1
Height = 7455
Left = 2880
OleObjectBlob = "Form1.frx":0000
TabIndex = 0
Top = 360
Width = 7215
End
Begin esriMapControl.MapControl MapControl1
Height = 2895
Left = 0
OleObjectBlob = "Form1.frx":0AA1
TabIndex = 1
Top = 4920
Width = 2895
End
Begin esriToolbarControl.ToolbarControl ToolbarControl1
Height = 390
Left = 0
OleObjectBlob = "Form1.frx":1156
TabIndex = 2
Top = 0
Width = 10095
End
Begin esriTOCControl.TOCControl TOCControl1
Height = 4575
Left = 0
OleObjectBlob = "Form1.frx":11C8
TabIndex = 3
Top = 360
Width = 2895
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private m_pAoInitialize As IAoInitialize 'The initialization object
Private m_pToolbarMenu As IToolbarMenu 'The popup menu
Private m_pEnvelope As IEnvelope 'The envelope drawn on the MapControl
Private m_pFillSymbol As ISimpleFillSymbol 'The symbol used to draw the envelope on the MapControl
Private WithEvents m_pTransformEvents As DisplayTransformation 'The PageLayoutControl's focus map events
Attribute m_pTransformEvents.VB_VarHelpID = -1
Private WithEvents m_pCustomizeDialogEvents As CustomizeDialog 'The customize dialog events
Attribute m_pCustomizeDialogEvents.VB_VarHelpID = -1
Private m_pCustomizeDialog As ICustomizeDialog 'The customize dialog used by the ToolbarControl
Private Sub Form_Load()
'Create a new AoInitialize object
Set m_pAoInitialize = New AoInitialize
If m_pAoInitialize Is Nothing Then
MsgBox "Unable to initialize. This application cannot run!"
Unload Form1
Exit Sub
End If
'Determine if the product is available
If m_pAoInitialize.IsProductCodeAvailable(esriLicenseProductCodeEngine) = esriLicenseAvailable Then
If m_pAoInitialize.Initialize(esriLicenseProductCodeEngine) <> esriLicenseCheckedOut Then
MsgBox "The initialization failed. This application cannot run!"
Unload Form1
Exit Sub
End If
Else
MsgBox "The ArcGIS Engine product is unavailable. This application cannot run!"
Unload Form1
Exit Sub
End If
'Create the customize dialog for the ToolbarControl
CreateCustomizeDialog
'Create symbol used on the MapConrol
CreateOverviewSymbol
'
'Set label editing to manual
TOCControl1.LabelEdit = esriTOCControlManual
'在Pagelayout中检查和加载地图文档
Dim sFileName As String
sFileName = "Maps\Yellowstone.mxd"
If PageLayoutControl1.CheckMxFile(sFileName) Then
PageLayoutControl1.LoadMxFile sFileName
End If
Dim sProgID As String
'Add generic commands
sProgID = "esriControlTools.ControlsOpenDocCommand"
ToolbarControl1.AddItem sProgID, , , False, , esriCommandStyleIconOnly
'添加PageLayout中的浏览工具
sProgID = "esriControlTools.ControlsPageZoomInTool"
ToolbarControl1.AddItem sProgID, , , True, , esriCommandStyleIconOnly
sProgID = "esriControlTools.ControlsPageZoomOutTool"
ToolbarControl1.AddItem sProgID, , , False, , esriCommandStyleIconOnly
sProgID = "esriControlTools.ControlsPagePanTool"
ToolbarControl1.AddItem sProgID, , , False, , esriCommandStyleIconOnly
sProgID = "esriControlTools.ControlsPageZoomWholePageCommand"
ToolbarControl1.AddItem sProgID, , , False, , esriCommandStyleIconOnly
sProgID = "esriControlTools.ControlsPageZoomPageToLastExtentBackCommand"
ToolbarControl1.AddItem sProgID, , , False, , esriCommandStyleIconOnly
sProgID = "esriControlTools.ControlsPageZoomPageToLastExtentForwardCommand"
ToolbarControl1.AddItem sProgID, , , False, , esriCommandStyleIconOnly
'添加Map浏览工具
sProgID = "esriControlTools.ControlsMapZoomInTool"
ToolbarControl1.AddItem sProgID, , , True, , esriCommandStyleIconOnly
sProgID = "esriControlTools.ControlsMapZoomOutTool"
ToolbarControl1.AddItem sProgID, , , False, , esriCommandStyleIconOnly
sProgID = "esriControlTools.ControlsMapPanTool"
ToolbarControl1.AddItem sProgID, , , False, , esriCommandStyleIconOnly
sProgID = "esriControlTools.ControlsMapFullExtentCommand"
ToolbarControl1.AddItem sProgID, , , False, , esriCommandStyleIconOnly
''Add custom date tool
' sProgID = "EngineScenarioCommands.AddDateTool"
' ToolbarControl1.AddItem sProgID, , , True, , esriCommandStyleIconAndText
'创建新的菜单
Set m_pToolbarMenu = New ToolbarMenu
'在菜单中添加命令
sProgID = "esriControlTools.ControlsPageZoomInFixedCommand"
m_pToolbarMenu.AddItem sProgID, , , False, esriCommandStyleIconAndText
sProgID = "esriControlTools.ControlsPageZoomOutFixedCommand"
m_pToolbarMenu.AddItem sProgID, , , False, esriCommandStyleIconAndText
sProgID = "esriControlTools.ControlsPageZoomWholePageCommand"
m_pToolbarMenu.AddItem sProgID, , , False, esriCommandStyleIconAndText
sProgID = "esriControlTools.ControlsPageZoomPageToLastExtentBackCommand"
m_pToolbarMenu.AddItem sProgID, , , False, esriCommandStyleIconAndText
sProgID = "esriControlTools.ControlsPageZoomPageToLastExtentForwardCommand"
m_pToolbarMenu.AddItem sProgID, , , True, esriCommandStyleIconAndText
'设置联系
TOCControl1.SetBuddyControl PageLayoutControl1
ToolbarControl1.SetBuddyControl PageLayoutControl1
'把此菜单与PageLayoutControl挂钩
m_pToolbarMenu.SetHook PageLayoutControl1
End Sub
Private Sub Form_Resize()
Dim dWidth As Double, dheight As Double, dMargin As Double
'Set the margin size
dMargin = TOCControl1.Left
'Resize the PageLayoutControl
dheight = Form1.ScaleHeight - PageLayoutControl1.Top - dMargin
If dheight > 0 Then PageLayoutControl1.Height = dheight
dWidth = Form1.ScaleWidth - TOCControl1.Width - (dMargin * 2)
If dWidth > 0 Then PageLayoutControl1.Width = dWidth
'Resize the MapControl
dheight = Form1.ScaleHeight - MapControl1.Top - dMargin
If dheight > 0 Then MapControl1.Height = dheight
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Shut down the AoInitilaize object
m_pAoInitialize.Shutdown
End Sub
Private Sub MapControl1_OnAfterDraw(ByVal display As Variant, ByVal viewDrawPhase As Long)
If m_pEnvelope Is Nothing Then Exit Sub
'If the foreground phase has drawn
Dim pViewDrawPhase As esriViewDrawPhase
pViewDrawPhase = viewDrawPhase
If pViewDrawPhase = esriViewForeground Then
'Draw the shape on the MapControl
MapControl1.DrawShape m_pEnvelope, m_pFillSymbol
End If
End Sub
Private Sub PageLayoutControl1_OnMouseDown(ByVal button As Long, ByVal shift As Long, ByVal x As Long, ByVal y As Long, ByVal pageX As Double, ByVal pageY As Double)
'右键弹出菜单
If button = vbRightButton Then
m_pToolbarMenu.PopupMenu x, y, PageLayoutControl1.hWnd
End If
End Sub
Private Sub PageLayoutControl1_OnPageLayoutReplaced(ByVal newPageLayout As Variant)
'Get the IActiveView of the focus map in the PageLayoutControl
Dim pActiveView As IActiveView
Set pActiveView = PageLayoutControl1.ActiveView.FocusMap
'Trap the ITranformEvents of the PageLayoutCntrol's focus map
Set m_pTransformEvents = pActiveView.ScreenDisplay.DisplayTransformation
'Get the extent of the focus map
Set m_pEnvelope = pActiveView.Extent
'加载相同的地图文档到MapControl中
MapControl1.LoadMxFile PageLayoutControl1.DocumentFilename
'Set the extent of the MapControl to the full extent of the data
MapControl1.Extent = MapControl1.FullExtent
End Sub
Private Sub TOCControl1_OnEndLabelEdit(ByVal x As Long, ByVal y As Long, ByVal newLabel As String, pcanEdit As Boolean)
'If the new label is an empty string then prevent the edit
If Trim(newLabel) = "" Then pcanEdit = False
End Sub
Private Sub CreateOverviewSymbol()
'Get the IRGBColor interface
Dim pColor As IRgbColor
Set pColor = New RgbColor
'Set the color properties
pColor.RGB = RGB(255, 0, 0)
'Get the ILine symbol interface
Dim pOutline As ILineSymbol
Set pOutline = New SimpleLineSymbol
'Set the line symbol properties
pOutline.Width = 1.5
pOutline.Color = pColor
'Get the IFillSymbol interface
Set m_pFillSymbol = New SimpleFillSymbol
'Set the fill symbol properties
m_pFillSymbol.Outline = pOutline
m_pFillSymbol.Style = esriSFSHollow
End Sub
Private Sub CreateCustomizeDialog()
Set m_pCustomizeDialog = New CustomizeDialog
Set m_pCustomizeDialogEvents = m_pCustomizeDialog
'Set the title
m_pCustomizeDialog.DialogTitle = "Customize ToolbarControl Items"
'Show the 'Add from File' button
m_pCustomizeDialog.ShowAddFromFile = True
'Set the ToolbarControl that new items will be added to
m_pCustomizeDialog.SetDoubleClickDestination ToolbarControl1
End Sub
Private Sub m_pCustomizeDialogEvents_OnCloseDialog()
ToolbarControl1.Customize = False
chkCustomize.Value = 0
End Sub
Private Sub m_pCustomizeDialogEvents_OnStartDialog()
ToolbarControl1.Customize = True
End Sub
Private Sub m_pTransformEvents_VisibleBoundsUpdated(ByVal sender As esriDisplay.IDisplayTransformation, ByVal sizeChanged As Boolean)
'Set the extent to the new visible extent
Set m_pEnvelope = sender.VisibleBounds
'Refresh the MapControl's foreground phase
MapControl1.Refresh
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -