avinzhang 发表于 2008-6-13 10:18:00

急!VBA中插入的文字对正方式为“中”的命令是什么啊?

<p>我用VBA写的小程序,在CAD图形中插入一行文字,但是文字都是居左对正,请问如何能把文字设置成居中对正啊?</p><p>我指的是文字居中对正的代码怎么写的啊?谢谢各位指点!</p>

alfalfa 发表于 2008-6-14 09:32:00

<pre class="Code">文档里面的例子<br/><br/>Sub Example_Alignment()<br/>   ' This example creates a text object in model space and<br/>   ' demonstrates setting the alignment of the new text string<br/>
                <br/>    Dim textObj As AcadText<br/>    Dim textString As String<br/>    Dim insertionPoint(0 To 2) As Double, alignmentPoint(0 To 2) As Double<br/>    Dim height As Double<br/>    Dim oldPDMODE As Integer<br/>    Dim pointObj As AcadPoint<br/>
                <br/>    ' Define the new Text object<br/>    textString = "Hello, World."<br/>    insertionPoint(0) = 3: insertionPoint(1) = 3: insertionPoint(2) = 0<br/>    alignmentPoint(0) = 3: alignmentPoint(1) = 3: alignmentPoint(2) = 0<br/>    height = 0.5<br/>
                <br/>    ' Create the Text object in model space<br/>    Set textObj = ThisDrawing.ModelSpace.AddText(textString, insertionPoint, height)<br/>
                <br/>    oldPDMODE = ThisDrawing.GetVariable("PDMODE")   ' Record existing point style<br/>
                <br/>    ' Create a crosshair over the text alignment point<br/>    ' to better visualize the alignment process<br/>    Set pointObj = ThisDrawing.ModelSpace.AddPoint(alignmentPoint)<br/>
                <br/>    ThisDrawing.SetVariable "PDMODE", 2             ' Set point style to crosshair<br/>
                <br/>    ThisDrawing.Application.ZoomAll<br/>
                <br/>    ' Set the text alignment to a value other than acAlignmentLeft, which is the default.<br/>    ' Create a point that will act as an alignment reference point<br/>    textObj.Alignment = acAlignmentRight<br/>
                <br/>    ' Create the text alignment reference point and the text will automatically<br/>    ' align to the right of this point, because the text<br/>    ' alignment was set to acAlignmentRight<br/>    textObj.TextAlignmentPoint = alignmentPoint<br/>    ThisDrawing.Regen acActiveViewport<br/>    MsgBox "The Text object is now aligned to the right of the alignment point"<br/>
                <br/>    ' Center the text to the alignment point<br/>    textObj.Alignment = acAlignmentCenter<br/>    ThisDrawing.Regen acActiveViewport<br/>    MsgBox "The Text object is now centered to the alignment point"<br/>
                <br/>    ' Reset point style<br/>    ThisDrawing.SetVariable "PDMODE", oldPDMODE<br/>End Sub</pre>

robbin840311 发表于 2008-6-14 15:51:00

楼上正解,个人觉得对齐方式修改为“中”后,可以把pointObj删除。
页: [1]
查看完整版本: 急!VBA中插入的文字对正方式为“中”的命令是什么啊?