CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ActiveX 开发指南

关于对齐行文本 (VBA/ActiveX)

2023-1-5 00:22| 发布者: admin| 查看: 652| 评论: 0|来自: AutoCAD

摘要: 您可以水平和垂直对齐行文本。左对齐是默认设置。若要设置水平和垂直对齐选项,请使用“对齐方式”属性。

您可以水平和垂直对齐行文本。左对齐是默认设置。若要设置水平和垂直对齐选项,请使用属性。Alignment

重新对齐文本

此示例创建一个对象和一个对象。对象设置为文本对齐点,并更改为红色十字准线,使其可见。更改文本对齐方式并显示一个消息框,以便停止宏执行。这使您可以查看更改文本对齐方式的影响。TextPointPoint

Sub Ch4_TextAlignment()
  Dim textObj As AcadText
  Dim textString As String
  Dim insertionPoint(0 To 2) As Double
  Dim height As Double

  ' Define the new Text object
  textString = "Hello, World."
  insertionPoint(0) = 3
  insertionPoint(1) = 3
  insertionPoint(2) = 0
  height = 0.5

  ' Create the Text object in model space
  Set textObj = ThisDrawing.ModelSpace.AddText(textString, insertionPoint, height)

  ' Create a point over the text alignment point,
  ' so we can better visualize the alignment process
  Dim pointObj As AcadPoint
  Dim alignmentPoint(0 To 2) As Double
  alignmentPoint(0) = 3
  alignmentPoint(1) = 3
  alignmentPoint(2) = 0
  Set pointObj = ThisDrawing.ModelSpace.AddPoint(alignmentPoint)
  pointObj.Color = acRed

  ' Set the point style to crosshair
  ThisDrawing.SetVariable "PDMODE", 2

  ' Align the text to the Left
  textObj.Alignment = acAlignmentLeft
  ThisDrawing.Regen acActiveViewport
  MsgBox "The Text object is now aligned left"

  ' Align the text to the Center
  textObj.Alignment = acAlignmentCenter

  ' Align the text to the point (necessary for
  ' all but left aligned text.)
  textObj.TextAlignmentPoint = alignmentPoint

  ThisDrawing.Regen acActiveViewport
  MsgBox "The Text object is now centered"

  ' Align the text to the Right
  textObj.Alignment = acAlignmentRight
  ThisDrawing.Regen acActiveViewport
  MsgBox "The Text object is now aligned right"
End Sub

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-5-11 23:47

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部