Share via


ShapeCollection.RemoveAt Method

Removes a Shape from the ShapeCollection at the specified indexed location.

Namespace:  Microsoft.VisualBasic.PowerPacks
Assembly:  Microsoft.VisualBasic.PowerPacks.Vs (in Microsoft.VisualBasic.PowerPacks.Vs.dll)

Syntax

'Declaration
Public Sub RemoveAt ( _
    index As Integer _
)
'Usage
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
)

Parameters

Implements

IList.RemoveAt(Int32)

Remarks

When a Shape is removed from the control collection, all subsequent shapes are moved up one position in the collection.

You can also remove a Shape by using the Remove method, or remove all shapes by using the Clear method.

To add new Shape objects to the collection, use the Add or AddRange method.

Examples

The following example demonstrates how to use the RemoveAt method to remove a Shape from a form if it is a member of the form's ShapeCollection. This example requires that you have at least two OvalShape controls on a form.

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);
    }
}

.NET Framework Security

See Also

Reference

ShapeCollection Class

ShapeCollection Members

Microsoft.VisualBasic.PowerPacks Namespace

Other Resources

Introduction to the Line and Shape Controls (Visual Studio)

How to: Draw Lines with the LineShape Control (Visual Studio)

How to: Draw Shapes with the OvalShape and RectangleShape Controls (Visual Studio)