Shapes.AddLine 方法 (Word)

在绘图画布上添加一条直线。

语法

表达式AddLine (BeginXBeginYEndXEndY)

expression 是必需的。 一个代表 Shapes 对象的变量。

参数

名称 必需/可选 数据类型 说明
BeginX 必需 Single 直线起点相对于绘图画布的水平位置(以磅为单位)。
BeginY 必需 Single 直线起点相对于绘图画布的垂直位置(以磅为单位)。
EndX 必需 Single 直线终点相对于绘图画布的水平位置(以磅为单位)。
EndY 必需 Single 直线终点相对于绘图画布的垂直位置(以磅为单位)。

返回值

Shape

备注

若要创建一个箭头,使用 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

另请参阅

Shapes 集合对象

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。