ShapeCollection.AddRange 方法
更新:2007 年 11 月
将一个 Shape 对象数组添加到 ShapeCollection。
命名空间: Microsoft.VisualBasic.PowerPacks
程序集: Microsoft.VisualBasic.PowerPacks.Vs(在 Microsoft.VisualBasic.PowerPacks.Vs.dll 中)
语法
声明
Public Sub AddRange ( _
shapes As Shape() _
)
用法
Dim instance As ShapeCollection
Dim shapes As Shape()
instance.AddRange(shapes)
public void AddRange(
Shape[] shapes
)
public:
void AddRange(
array<Shape^>^ shapes
)
public function AddRange(
shapes : Shape[]
)
参数
shapes
类型:array<Microsoft.VisualBasic.PowerPacks.Shape[]要添加到集合的 Shape 对象数组。
备注
shapes 数组中包含的 Shape 对象将添加到集合的末尾。
您可以使用 AddRange 方法将一组 Shape 对象快速添加到集合中。这比使用 Add 方法将每个 Shape 手动添加到集合中要快。
若要移除以前添加的 Shape,请使用 Remove、RemoveAt 或 Clear 方法。
对继承者的说明:
在派生类中重写 AddRange 时,一定要调用基类的 AddRange 方法,以保证将形状添加到集合中。
示例
下面的示例将一组 OvalShape 控件添加到窗体的 ShapeCollection。此示例要求窗体上有一个 RectangleShape 控件。
Private Sub RectangleShape1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles RectangleShape1.Click
' Create two oval shapes to add to the form.
Dim oval1 As OvalShape = New OvalShape()
Dim oval2 As OvalShape = New OvalShape()
' Set the size of the ovals.
oval1.Size = New Size(100, 200)
oval2.Size = oval1.Size
' Set the appropriate location of ovals.
oval1.Location = New Point(10, 10)
oval2.Location = New Point(oval1.Left + 10, oval1.Top + 10)
' Add the controls to the form by using the AddRange method.
RectangleShape1.Parent.Shapes.AddRange(New Shape() {oval1, oval2})
End Sub
private void rectangleShape1_Click(System.Object sender, System.EventArgs e)
{
// Create two oval shapes to add to the form.
OvalShape oval1 = new OvalShape();
OvalShape oval2 = new OvalShape();
// Set the size of the ovals.
oval1.Size = new Size(100, 200);
oval2.Size = oval1.Size;
// Set the appropriate location of ovals.
oval1.Location = new Point(10, 10);
oval2.Location = new Point(oval1.Left + 10, oval1.Top + 10);
// Add the controls to the form by using the AddRange method.
rectangleShape1.Parent.Shapes.AddRange(new Shape[] { oval1, oval2 });
}
权限
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。
另请参见
参考
Microsoft.VisualBasic.PowerPacks 命名空间
其他资源
Line 和 Shape 控件简介 (Visual Studio)