'*****************************************************************
'如何在Page Layout 上添加Text
'本例要实现的功能是根据鼠标在Page Layout 上点击的位置添加Text 元素。
'要点
'要实现本例的功能,首先需要在PageLayout 上创建一个Text 元素,然后再
'设置该元素的属性?其中主要使用了两个接口ITextElement 和
'IGraphicsContainer
'ITextElement 接口是用来控制Text 元素,以下是它的几个主要属性:
'ScaleText:BOOL 型,表示地图比例尺变化时Text 大小是否变化;
'Symbol:用来设置Text 元素的风格;
'Text: 用来设置Text 元素的内容?
'IGraphicsContainer 是用来控制PageLayout, Map 等对象上图形元素的接口。
'以下是它的几个主要属性和方法:
'AddElement:向层中增加一个元素;
'DeleteAllElements:删除所有的元素;
'FindFrame:查找可以放在该容器中的某对象,例如Text 元素;
'Next:返回该容器中的下一个对象;
'UpdateElement: 更新某个元素
'函数AddTextToLayout 根据鼠标点击的位置点(x,y)在PageLayout 上添加一
'个文本元素
'程序说明
'函数AddTextToLayout 根据鼠标点击的位置点(x,y)在PageLayout 上添加一
'个文本元素
'******************************************************************
Sub AddTextToLayout(X As Long, Y As Long)
Dim pActiveView As IActiveView
Dim pGraphicsContainer As IGraphicsContainer
Dim pTextElement As ITextElement
Dim pElement As IElement
On Error GoTo ErrorHandler
Set pActiveView = PageLayoutControl1.PageLayout
Set pGraphicsContainer = PageLayoutControl1.PageLayout
Set pTextElement = New TextElement
Set pElement = pTextElement
'设置Text 的内容
pTextElement.Text = "My Map"
'将元素的图形定位在点(x,y)处
pElement.Geometry= pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y)
'向PageLayout 中添加一个元素
pGraphicsContainer.AddElement pTextElement, 0
'刷新
PageLayoutControl1.ActiveView.PartialRefresh esriViewGraphics, Nothing, Nothing
Exit Sub
ErrorHandler:
MsgBox Err.Description
End Sub
|
(本文已被浏览 次) | | |