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
)
参数
value
类型:Microsoft.VisualBasic.PowerPacks.Shape要添加到 Shape 的 ShapeCollection。
备注
您可以通过 Add 方法将 Shape 对象添加到 ShapeCollection 的末尾。
还可以使用 AddRange 方法向集合中添加新的 Shape 对象。
若要移除以前添加的 Shape,请使用 Remove、RemoveAt 或 Clear 方法。
对继承者的说明:
在派生类中重写 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);
}
权限
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。
另请参见
参考
Microsoft.VisualBasic.PowerPacks 命名空间
其他资源
Line 和 Shape 控件简介 (Visual Studio)