应用于 CanvasShapes 对象的 AddLine 方法。
在画布上添加一条直线。返回一个代表该直线的 Shape 对象,并将其添加到 CanvasShapes 集合。
expression.AddLine(BeginX, BeginY, EndX, EndY)
expression 必需。该表达式返回一个 CanvasShapes 对象。
BeginX Single 类型,必需。直线起点相对于画布的水平位置,以磅为单位。
BeginY Single 类型,必需。直线起点相对于画布的垂直位置,以磅为单位。
EndX Single 类型,必需。直线终点相对于画布的水平位置,以磅为单位。
EndY Single 类型,必需。直线终点相对于画布的垂直位置,以磅为单位。
在文档中添加一条直线。返回一个代表该直线的 Shape 对象,并将其添加到 Shapes 集合。
expression.AddLine(BeginX, BeginY, EndX, EndY, Anchor)
expression 必需。该表达式返回一个 Shapes 对象。
BeginX Single 类型,必需。直线起点相对于锁定标记的水平位置,以磅为单位。
BeginY Single 类型,必需。直线起点相对于锁定标记的垂直位置,以磅为单位。
EndX Single 类型,必需。直线终点相对于锁定标记的水平位置,以磅为单位。
EndY Single 类型,必需。直线终点相对于锁定标记的垂直位置,以磅为单位。
Anchor Variant 类型,可选。代表与标签绑定文本的Range 对象。如果指定 Anchor,则锁定标记位于锁定区域中第一段的起始位置。如果省略该参数,将自动选定锁定区域,而标签将相对于页面的上部和左侧边缘进行定位。
若要创建带箭头的直线,请使用 Line 属性来设置线条格式。
本示例在新画布上添加一条紫色带箭头的直线。
Sub NewCanvasLine()
Dim shpCanvas As Shape
Dim shpLine As Shape
'Add new drawing canvas to the active document
Set shpCanvas = ActiveDocument.Shapes _
.AddCanvas(Left:=100, Top:=75, _
Width:=150, Height:=200)
'Add a line to the drawing canvas
Set shpLine = shpCanvas.CanvasItems.AddLine( _
BeginX:=25, BeginY:=25, EndX:=150, EndY:=150)
'Add an arrow to the line and sets the color to purple
With shpLine.Line
.BeginArrowheadStyle = msoArrowheadDiamond
.BeginArrowheadWidth = msoArrowheadWide
.ForeColor.RGB = RGB(Red:=150, Green:=0, Blue:=255)
End With
End Sub
本示例在活动文档中添加一条直线,然后设置其格式为带箭头的红色直线。
Sub NewLine()
Dim lineNew As Shape
'Add new line to document
Set lineNew = ActiveDocument.Shapes.AddLine_
(Left:=100, Top:=100, Width:=60, Height:=20)
'Format line
With lineNew.Line
.BeginArrowheadStyle = msoArrowheadNone
.EndArrowheadStyle = msoArrowheadTriangle
.ForeColor.RGB = RGB(Red:=128, Green:=0, Blue:=0)
End With
End Sub