ShapeCollection Class

Represents a collection of Shape objects.

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

Syntax

'Declaration
Public NotInheritable Class ShapeCollection _
    Implements IList, IDisposable
'Usage
Dim instance As ShapeCollection
public sealed class ShapeCollection : IList, 
    IDisposable
public ref class ShapeCollection sealed : IList, 
    IDisposable
public final class ShapeCollection implements IList, IDisposable

Remarks

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.

Examples

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

Inheritance Hierarchy

System.Object
  Microsoft.VisualBasic.PowerPacks.ShapeCollection

Thread Safety

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

See Also

Reference

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)