ShapeCollection Class

 

Represents a collection of Shape objects.

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

System.Object
  Microsoft.VisualBasic.PowerPacks.ShapeCollection

public sealed class ShapeCollection : IList, IDisposable

NameDescription
System_CAPS_pubmethodShapeCollection(ShapeContainer)

Initializes a new instance of the ShapeCollection class.

NameDescription
System_CAPS_pubpropertyCount

Gets the number of shapes in the collection.

System_CAPS_pubpropertyIsReadOnly

Gets a value indicating whether a collection is read-only.

System_CAPS_pubpropertyItem[Int32]

Gets the Shape at the specified indexed location in the collection.

System_CAPS_pubpropertyOwner

Gets the ShapeContainer that owns the ShapeCollection.

NameDescription
System_CAPS_pubmethodAdd(Shape)

Adds the specified Shape to the ShapeCollection.

System_CAPS_pubmethodAddRange(Shape[])

Adds an array of Shape objects to the ShapeCollection.

System_CAPS_pubmethodClear()

Removes all shapes from the collection.

System_CAPS_pubmethodContains(Shape)

Determines whether the specified Shape is a member of the collection.

System_CAPS_pubmethodContainsKey(String)

Determines whether the ShapeCollection contains an item with the specified key.

System_CAPS_pubmethodCopyTo(Shape[], Int32)

Copies the whole ShapeCollection to a compatible one-dimensional Array, starting at the specified index of the destination array.

System_CAPS_pubmethodDispose()

Releases the unmanaged resources used by the ShapeCollection.

System_CAPS_pubmethodEquals(Object)

(Inherited from Object.)

System_CAPS_pubmethodGetChildIndex(Shape)

Retrieves the index of the specified Shape in the ShapeCollection.

System_CAPS_pubmethodGetChildIndex(Shape, Boolean)

Retrieves the index of the specified Shape in the ShapeCollection, and optionally raises an exception if the specified Shape is not in the ShapeCollection.

System_CAPS_pubmethodGetEnumerator()

Retrieves a reference to an enumerator object that is used to iterate over a ShapeCollection.

System_CAPS_pubmethodGetHashCode()

(Inherited from Object.)

System_CAPS_pubmethodGetType()

(Inherited from Object.)

System_CAPS_pubmethodIndexOf(Shape)

Retrieves the index of the specified Shape in the ShapeCollection.

System_CAPS_pubmethodIndexOfKey(String)

Retrieves the index of the first occurrence of the specified item in the collection.

System_CAPS_pubmethodRemove(Shape)

Removes the specified Shape from the ShapeCollection.

System_CAPS_pubmethodRemoveAt(Int32)

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

System_CAPS_pubmethodSetChildIndex(Shape, Int32)

Sets the index of the specified Shape in the ShapeCollection to the specified index value.

System_CAPS_pubmethodToString()

(Inherited from Object.)

NameDescription
System_CAPS_pubinterfaceSystem_CAPS_privmethodICollection.CopyTo(Array, Int32)

Copies the ShapeCollection object to a compatible one-dimensional Array, starting at the specified index of the destination array.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIList.Add(Object)

Adds the specified object to the collection.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIList.Contains(Object)

Determines whether the specified object is in the collection.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIList.IndexOf(Object)

Retrieves the index of the specified object in the collection.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIList.Insert(Int32, Object)

Inserts the object at the specified index.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIList.Remove(Object)

Removes the specified object from the collection.

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 void Shapes_Click(System.Object sender, System.EventArgs e)
{
    // Determine whether the shape is in the collection.
    if (shapeContainer1.Shapes.Contains((Shape)sender))
    // If the Index is greater than 0, remove the shape.
    {
        if (shapeContainer1.Shapes.IndexOf((Shape)sender) > 0)
        {
            shapeContainer1.Shapes.Remove((Shape)sender);
        }
    }
}

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: