Represents a collection of Shape objects.
Assembly: Microsoft.VisualBasic.PowerPacks (in Microsoft.VisualBasic.PowerPacks.dll)
The Add, Remove, and RemoveAt methods enable you to add and remove individual shapes from the collection. You can also use the AddRange or Clear method to add or remove all the shapes from the collection.
You can determine whether a Shape is a member of the collection by passing the shape into the Contains method. To get the index value of the location of a shape in the collection, pass the shape into the IndexOf method. You can copy the collection into an array by calling the CopyTo method.
The following code example removes a Shape from the ShapeCollection of a form if it is a member of the collection. The example requires that you have a LineShape, an OvalShape, and a RectangleShape control on a form. When a shape is clicked, it is removed from the ShapeCollection unless it is the last shape in the collection.
Private Sub Shapes_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles RectangleShape1.Click, _ OvalShape1.Click, LineShape1.Click ' Determine whether the shape is in the collection. If ShapeContainer1.Shapes.Contains(sender) Then ' If the Index is greater than 0, remove the shape. If ShapeContainer1.Shapes.IndexOf(sender) > 0 Then ShapeContainer1.Shapes.Remove(sender) End If End If End Sub