ShapeContainer.Shapes Property

Gets the collection of shapes that are contained in the ShapeContainer.

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

Syntax

'Declaration
<BrowsableAttribute(False)> _
Public ReadOnly Property Shapes As ShapeCollection
[BrowsableAttribute(false)]
public ShapeCollection Shapes { get; }
[BrowsableAttribute(false)]
public:
property ShapeCollection^ Shapes {
    ShapeCollection^ get ();
}
[<BrowsableAttribute(false)>]
member Shapes : ShapeCollection with get
function get Shapes () : ShapeCollection

Property Value

Type: Microsoft.VisualBasic.PowerPacks.ShapeCollection
A ShapeCollection representing the collection of shapes that are contained in the ShapeContainer.

Remarks

A ShapeCollection acts as a parent to a collection of shapes. For example, when several shapes are added to a Form, each shape is a member of the ShapeCollection assigned to the ShapeContainer of the form.

You can work with the shapes in the ShapeCollection assigned to a ShapeContainer by using the methods available in the ShapeCollection class.

When you add several shapes to a ShapeContainer, we recommend that you call the SuspendLayout method before initializing the shapes to be added. After you add the shapes to the ShapeContainer, call the ResumeLayout method. Using SuspendLayout and ResumeLayout will increase the performance of applications that have many shapes.

Examples

The following example removes a Shape from the ShapeCollection of a form (represented by the Shapes property) if it is a member of the collection. This 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);
        }
    }
}

.NET Framework Security

See Also

Reference

ShapeContainer Class

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)