sirc_lizheng
伴读书童
伴读书童
  • 注册日期2004-07-09
  • 发帖数148
  • QQ
  • 铜币495枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:2531回复:6

请教arcengine 中添加text的代码问题!

楼主#
更多 发布于:2008-10-23 15:56
Public Function AddText(x As Long, y As Long)<BR>    Dim pMxDocument As IMapDocument 'IMxDocument<BR>    Dim pActiveView As IActiveView<BR>    Dim pGraphicsContainer As IGraphicsContainer<BR>    Dim pTextElement As ITextElement<BR>    Dim pElement As IElement<BR>On Error GoTo ErrorHandler<BR>    Set pMxDocument = frmmain.MapControl1.DocumentMap ' ThisDocument<BR>    Set pActiveView = pMxDocument.ActiveView<BR>    Set pGraphicsContainer = pMxDocument.ActiveView<BR>    Set pTextElement = New TextElement<BR>    Set pElement = pTextElement<BR>    '设置Text元素的内容<BR>    pTextElement.Text = "My Map"<BR>    '将元素的图形定位在点(x,y)处<BR>    pElement.Geometry = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y)<BR>    '向Map中添加元素<BR>    pGraphicsContainer.AddElement pTextElement, 0<BR>    '刷新<BR>    pMxDocument.ActiveView.PartialRefresh esriViewGraphics, Nothing, Nothing<BR>    Exit Function<BR>ErrorHandler:<BR>    MsgBox Err.Description<BR>End Function
喜欢0 评分0
sirc_lizheng
伴读书童
伴读书童
  • 注册日期2004-07-09
  • 发帖数148
  • QQ
  • 铜币495枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2008-10-23 15:57
提示错误!
提示语法错误,不知道是哪个地方?
举报 回复(0) 喜欢(0)     评分
sirc_lizheng
伴读书童
伴读书童
  • 注册日期2004-07-09
  • 发帖数148
  • QQ
  • 铜币495枚
  • 威望0点
  • 贡献值0点
  • 银元0个
2楼#
发布于:2008-10-23 16:51
修改的代码如下,不知道为什么,没有反应!
<P>修改的代码如下,不知道为什么,没有反应!</P>
<P>Public Function AddTextToLayout(x As Long, y As Long) ' Add it by lizheng at 20080905<BR>    'pagelayoutcontrol中添加文本<BR>    Dim pActiveView As IActiveView<BR>    Dim pGraphicsContainer As IGraphicsContainer<BR>    Dim pTextElement As ITextElement<BR>    Dim pElement As IElement</P>
<P>    On Error GoTo ErrorHandler<BR>    '确保ArcMap 在layout 模式下<BR>    'If Not pMxDocument.ActiveView Is pMxDocument.PageLayout Then Exit Sub<BR>    <BR>    Set pActiveView = frmmain.PageLayoutControl1.ActiveView<BR>    Set pGraphicsContainer = frmmain.PageLayoutControl1.ActiveView<BR>    Set pTextElement = New TextElement<BR>    Set pElement = pTextElement<BR>    '设置Text 的内容<BR>    pTextElement.Text = "文本888"<BR>    '将元素的图形定位在点(x,y)处<BR>    pElement.Geometry = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y)<BR>    '向PageLayout 中添加一个元素<BR>    pGraphicsContainer.AddElement pTextElement, 0<BR>    '刷新frmmain.PageLayoutControl1.ActiveView.<BR>    pActiveView.PartialRefresh esriViewGraphics, Nothing, Nothing<BR>    Exit Function<BR>ErrorHandler:<BR>    MsgBox Err.Description<BR>End Function</P>
举报 回复(0) 喜欢(0)     评分
cl991036
管理员
管理员
  • 注册日期2003-07-25
  • 发帖数5913
  • QQ14265545
  • 铜币29656枚
  • 威望213点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • GIS帝国铁杆
3楼#
发布于:2008-10-24 19:27
2个控件的刷新不一样。
没钱又丑,农村户口。头可断,发型一定不能乱。 邮箱:gisempire@qq.com
举报 回复(0) 喜欢(0)     评分
sirc_lizheng
伴读书童
伴读书童
  • 注册日期2004-07-09
  • 发帖数148
  • QQ
  • 铜币495枚
  • 威望0点
  • 贡献值0点
  • 银元0个
4楼#
发布于:2008-10-28 11:28
问题解决了,但是在mapcontrol中就不行了,没有反应!
举报 回复(0) 喜欢(0)     评分
sirc_lizheng
伴读书童
伴读书童
  • 注册日期2004-07-09
  • 发帖数148
  • QQ
  • 铜币495枚
  • 威望0点
  • 贡献值0点
  • 银元0个
5楼#
发布于:2008-11-04 11:30
'mapcontrol中添加文本或标题,没有反应
<P>'mapcontrol中添加文本或标题<BR>Public Function AddmTextToLayout()  ' Add it by lizheng at 20081023<BR>    Dim textType As String<BR>On Error GoTo ErrorHandler<BR>    Set pTextActiveView = frmmain.MapControl1.ActiveView<BR>    Set pTextGraphicsContainer = frmmain.MapControl1.Map<BR>    Set pTextTextElement = New TextElement<BR>    Set pTextArea = pTextActiveView.Extent</P>
<P>    '第一步建立一个颜色。利用RGB颜色<BR>    Set pTextRGBcolor = New RgbColor<BR>    pTextRGBcolor.Blue = 0<BR>    pTextRGBcolor.Red = 255<BR>    pTextRGBcolor.Green = 0<BR>    <BR>    '第二步,建立一个font<BR>    Set pTextFontDisp = New stdole.StdFont<BR>    pTextFontDisp.Name = "Arial"<BR>    pTextFontDisp.Bold = False<BR>    pTextFontDisp.Underline = False<BR>    <BR>    '第三步建立一个将要添加的TextSymbol<BR>    Set pTTextSymbol = New TextSymbol<BR>    pTTextSymbol.Font = pTextFontDisp<BR>    pTTextSymbol.color = pTextRGBcolor<BR>    <BR>    If textType = "标题" Then<BR>        pTTextSymbol.Size = 40<BR>    ElseIf textType = "文本" Then<BR>        pTTextSymbol.Size = 20<BR>    End If<BR>    <BR>    '第四步,把TextSymbol和text属性赋给TextElement,并把TextElement赋给Element<BR>    pTextTextElement.Symbol = pTTextSymbol<BR>    If textType = "标题" Then<BR>        pTextTextElement.Text = "标题"<BR>    ElseIf textType = "文本" Then<BR>        pTextTextElement.Text = "文本"<BR>    End If<BR>    Set pTextElement = pTextTextElement<BR>    pTextElement.Geometry = pTextArea.Centroid<BR>    <BR>    '第五步,向PageLayout 中添加一个Element元素<BR>    pTextGraphicsContainer.AddElement pTextElement, 0<BR>    <BR>    '第六步,刷新frmmain.PageLayoutControl1.ActiveView.<BR>    pTextActiveView.PartialRefresh esriViewGraphics, Nothing, Nothing<BR>    Exit Function<BR>ErrorHandler:<BR>    MsgBox Err.Description</P>

<P>没有反应,不知道是什么错误!请您指点!</P>
举报 回复(0) 喜欢(0)     评分
sirc_lizheng
伴读书童
伴读书童
  • 注册日期2004-07-09
  • 发帖数148
  • QQ
  • 铜币495枚
  • 威望0点
  • 贡献值0点
  • 银元0个
6楼#
发布于:2008-11-05 11:18
问题解决了,谢谢好心人
举报 回复(0) 喜欢(0)     评分
游客

返回顶部