ShapeCollection.RemoveAt Method (Int32)
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
public void RemoveAt(
int index
)
public:
virtual void RemoveAt(
int index
) sealed
abstract RemoveAt :
index:int -> unit
override RemoveAt :
index:int -> unit
Public Sub RemoveAt (
index As Integer
)
Parameters
index
Type: System.Int32The index value of the Shape to remove.
Implements
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 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);
}
}
Private Sub OvalShape2_Click() 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
See Also
ShapeCollection Class
Microsoft.VisualBasic.PowerPacks Namespace
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)
Return to top