ShapeCollection.Add 方法

更新:2007 年 11 月

将指定的 Shape 添加到 ShapeCollection

命名空间:  Microsoft.VisualBasic.PowerPacks
程序集:  Microsoft.VisualBasic.PowerPacks.Vs(在 Microsoft.VisualBasic.PowerPacks.Vs.dll 中)

语法

声明
Public Sub Add ( _
    value As Shape _
)
用法
Dim instance As ShapeCollection
Dim value As Shape

instance.Add(value)
public void Add(
    Shape value
)
public:
void Add(
    Shape^ value
)
public function Add(
    value : Shape
)

参数

备注

您可以通过 Add 方法将 Shape 对象添加到 ShapeCollection 的末尾。

还可以使用 AddRange 方法向集合中添加新的 Shape 对象。

若要移除以前添加的 Shape,请使用 RemoveRemoveAtClear 方法。

对继承者的说明:

在派生类中重写 Add 时,一定要调用基类的 Add 方法,以保证将 Shape 添加到 ShapeCollection

示例

下面的示例向窗体的 ShapeCollection 中添加一个新的 Shape。此示例要求窗体上有一个 RectangleShape 控件。

Private Sub RectangleShape1_Click(ByVal sender As System.Object, _
 ByVal e As System.EventArgs) Handles RectangleShape1.Click
    ' Declare a new oval shape to add to the form.
    Dim oval As OvalShape = New OvalShape()
    ' Add the oval shape to the form.
    RectangleShape1.Parent.Shapes.Add(oval)
    oval.Location = New Point(50, 50)
    oval.Size = New Size(200, 100)
End Sub
private void rectangleShape1_Click(System.Object sender, System.EventArgs e)
{
    // Declare a new oval shape to add to the form.
    OvalShape oval = new OvalShape();
    // Add the oval shape to the form.
    rectangleShape1.Parent.Shapes.Add(oval);
    oval.Location = new Point(50, 50);
    oval.Size = new Size(200, 100);
}

权限

另请参见

参考

ShapeCollection 类

ShapeCollection 成员

Microsoft.VisualBasic.PowerPacks 命名空间

其他资源

Line 和 Shape 控件简介 (Visual Studio)

如何:使用 LineShape 控件绘制直线 (Visual Studio)

如何:使用 OvalShape 和 RectangleShape 控件绘制形状 (Visual Studio)