ShapeCollection.RemoveAt 方法

更新:2007 年 11 月

移除 ShapeCollection 中指定索引处的 Shape

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

语法

声明
Public Sub RemoveAt ( _
    index As Integer _
)
用法
Dim instance As ShapeCollection
Dim index As Integer

instance.RemoveAt(index)
public void RemoveAt(
    int index
)
public:
virtual void RemoveAt(
    int index
) sealed
public final function RemoveAt(
    index : int
)

参数

实现

IList.RemoveAt(Int32)

备注

当从控件集合中移除 Shape 时,所有后续形状都在集合中向上移动一个位置。

还可以使用 Remove 方法来移除单个 Shape,或者使用 Clear 方法来移除所有形状。

若要向集合中添加新的 Shape 对象,请使用 AddAddRange 方法。

示例

下面的示例演示如何使用 RemoveAt 方法从窗体中移除 Shape,但前提是该形状是窗体的 ShapeCollection 的成员。此示例要求窗体上至少有两个 OvalShape 控件。

Private Sub OvalShape2_Click(ByVal sender As System.Object, _
 ByVal e As System.EventArgs) Handles OvalShape2.Click
    Dim i As Integer
    ' Find the index for OvalShape1.
    i = OvalShape2.Parent.Shapes.GetChildIndex(OvalShape1, False)
    ' If the shape is not in the collection, display a message.
    If i = -1 Then
        MsgBox("OvalShape1 is not in this collection.")
    Else
        ' Remove the shape.
        OvalShape2.Parent.Shapes.RemoveAt(i)
    End If
End Sub
private void ovalShape2_Click(System.Object sender, System.EventArgs e)
{
    int i;
    // Find the index for OvalShape1.
    i = ovalShape2.Parent.Shapes.GetChildIndex(ovalShape1, false);
    // If the shape is not in the collection, display a message.
    if (i == -1)
    {
        MessageBox.Show("ovalShape1 is not in this collection.");
    }
    else
    {
        // Remove the shape.
        ovalShape2.Parent.Shapes.RemoveAt(i);
    }
}

权限

另请参见

参考

ShapeCollection 类

ShapeCollection 成员

Microsoft.VisualBasic.PowerPacks 命名空间

其他资源

Line 和 Shape 控件简介 (Visual Studio)

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

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