📄 vba16-11.txt
字号:
Private Sub AddScalebar(pElement As IElement)
' Add a scalebar for the given
' map frame.
Dim pMxDocument As IMxDocument
Dim pPageLayout As IPageLayout
Dim pPage As IPage
Dim pActiveView As IActiveView
Dim dblPageWidth As Double
Dim dblPageHeight As Double
Dim dblMargin As Double
Dim pID As New UID
Dim dblFrameWidth As Double
Dim dblFrameHeight As Double
Dim pMapFrame As IMapFrame
Dim pMapSurroundFrame As IMapSurroundFrame
Dim pScalebarElement As IElement
Dim pEnvelope As IEnvelope
Dim pFrameElement As IFrameElement
Dim pGraphicsContainer As IGraphicsContainer
Dim dblX As Double
Dim dblY As Double
' Get the page size.
Set pMxDocument = Application.Document
Set pPageLayout = pMxDocument.PageLayout
Set pActiveView = pPageLayout
Set pGraphicsContainer = pPageLayout
Set pPage = pPageLayout.Page
pPage.QuerySize dblPageWidth, dblPageHeight
dblMargin = 0.5
' Frame's width & height.
dblFrameWidth = 2
dblFrameHeight = 0.3
' Create a scalebar map surround.
Set pMapFrame = pElement
pID.Value = "esriCore.Scalebar"
Dim pMapSurround As IMapSurround
Set pMapSurround = New AlternatingScaleBar
Set pMapSurroundFrame = pMapFrame. _
CreateSurroundFrame(pID, pMapSurround)
' Size and position the scalebar.
Set pFrameElement = pMapSurroundFrame
Set pScalebarElement = pFrameElement
Set pEnvelope = New Envelope
' X and Y of upper left corner
dblX = dblPageWidth - (dblMargin + dblFrameWidth)
dblY = dblMargin + dblFrameHeight
pEnvelope.PutCoords dblX, (dblY - dblFrameHeight), _
(dblX + dblFrameWidth), dblY
' Scale the rectangle to fit the
' scalebar inside the rectangle
' drawn for the north arrow.
pEnvelope.Expand 0.9, 0.9, True
pScalebarElement.Geometry = pEnvelope
' Add the scalebar to the page layout.
pScalebarElement.Activate pActiveView.ScreenDisplay
pGraphicsContainer.AddElement pScalebarElement, 0
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -