对齐单行文字

AutoCAD ActiveX/VBA

 
对齐单行文字
 
 
 

可以在水平和垂直方向对齐单行文字。左对齐是默认选项。要设置水平和垂直对齐选项,请使用 Alignment 特性。

重新对齐文字

本例创建一个 Text 对象和一个 Point 对象。Point 对象被设置为文字对齐点,并变为红色的十字光标,使其可见。文字对齐将被修改,并显示消息框以终止宏的执行,这样用户就可以查看修改文字对齐的影响。

Sub Ch4_TextAlignment()
    Dim textObj As AcadText
    Dim textString As String
    Dim insertionPoint(0 To 2) As Double
    Dim height As Double
      
    ' 定义新的 Text 对象
    textString = "Hello, World."
    insertionPoint(0) = 3
    insertionPoint(1) = 3
    insertionPoint(2) = 0
    height = 0.5
      
    ' 在模型空间中创建 Text 对象
    Set textObj = ThisDrawing.ModelSpace. _
                    AddText(textString, insertionPoint, height)
      
    ' 在文字对齐点上创建一个点,
    ' 以便更清楚地看到对齐过程
    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
      
    ' 将点样式设置为十字光标
    ThisDrawing.SetVariable "PDMODE", 2
      
   ' 左对齐文字
    textObj.Alignment = acAlignmentLeft
    ThisDrawing.Regen acActiveViewport
    MsgBox "The Text object is now aligned left"
      
    ' 居中对齐文字
    textObj.Alignment = acAlignmentCenter
      
    ' 将文字对齐点(所有文字,
    ' 左对齐的文字除外。)
    textObj.TextAlignmentPoint = alignmentPoint
      
    ThisDrawing.Regen acActiveViewport
    MsgBox "The Text object is now centered"
      
    ' 右对齐文字
    textObj.Alignment = acAlignmentRight
    ThisDrawing.Regen acActiveViewport
    MsgBox "The Text object is now aligned right"
      
End Sub