📄 vba16-12.txt
字号:
Private Sub AddText()
' Add to two text elements for
' title and subtitle; and refresh
' the page layout.
Dim pMxDocument As IMxDocument
Dim pPageLayout As IPageLayout
Dim pActiveView As IActiveView
Dim pGraphicsContainer As IGraphicsContainer
Dim pGraphicsContainerSelect As IGraphicsContainerSelect
Dim pPage As IPage
Dim dblPageWidth As Double
Dim dblPageHeight As Double
Dim dblMargin As Double
Dim dblFrameWidth As Double
Dim dblFrameHeight As Double
Dim pEnvelope As IEnvelope
Dim pPoint As IPoint
Dim dblX As Double
Dim dblY As Double
Dim pTextElement As ITextElement
Dim pElement As IElement
Dim pTextSymbol As ITextSymbol
' Get the page size.
Set pMxDocument = Application.Document
Set pPageLayout = pMxDocument.PageLayout
Set pActiveView = pPageLayout
Set pGraphicsContainer = pPageLayout
Set pGraphicsContainerSelect = pPageLayout
Set pPage = pPageLayout.Page
pPage.QuerySize dblPageWidth, dblPageHeight
dblMargin = c_dblMargin
' Frame width is the page width
' less the margins and 2 inches
' for other frames.
' Frame height is 2 inches.
dblFrameWidth = dblPageWidth - (2 * dblMargin + 2)
dblFrameHeight = 2
' X and Y of the upper left corner.
dblX = dblMargin
dblY = dblMargin + dblFrameHeight
' Draw a rectangle to house the
' two text elements.
Set pEnvelope = New Envelope
pEnvelope.PutCoords dblX, (dblY - dblFrameHeight), _
(dblX + dblFrameWidth), dblY
AddRectangle pEnvelope
' Create the title text element.
Set pTextElement = New TextElement
pTextElement.Text = "Double click here to add text"
Set pTextSymbol = pTextElement.Symbol
pTextSymbol.Size = 24
pTextSymbol.HorizontalAlignment = esriTHACenter
pTextElement.Symbol = pTextSymbol
Set pElement = pTextElement
Set pPoint = New Point
pPoint.X = dblMargin + (dblFrameWidth / 2)
pPoint.Y = dblMargin + (2 * dblFrameHeight / 3)
' Position the text title and add it
' to the page layout.
pElement.Geometry = pPoint
pGraphicsContainer.AddElement pTextElement, 0
' Create the subtitle text element.
Set pTextElement = New TextElement
pTextElement.Text = "Double click here to add text"
Set pTextSymbol = pTextElement.Symbol
pTextSymbol.Size = 14
pTextSymbol.HorizontalAlignment = esriTHACenter
pTextElement.Symbol = pTextSymbol
Set pElement = pTextElement
Set pPoint = New Point
pPoint.X = dblMargin + (dblFrameWidth / 2)
pPoint.Y = dblMargin + (dblFrameHeight / 3)
' Position the text title and add it
' to the page layout.
pElement.Geometry = pPoint
pGraphicsContainer.AddElement pTextElement, 0
' Done. Unselect all layout elements
' and refresh the page layout.
pGraphicsContainerSelect.UnselectAllElements
pActiveView.Refresh
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -