Share via


ShapeCollection.Clear Method

Removes all shapes from the collection.

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

Syntax

'Declaration
Public Sub Clear
public void Clear()
public:
virtual void Clear() sealed
abstract Clear : unit -> unit  
override Clear : unit -> unit
public final function Clear()

Implements

IList.Clear()

Remarks

You can use the Clear method to remove the whole collection of shapes from a ShapeContainer.

To remove an individual shape from the collection, use the Remove or RemoveAt method.

To add new Shape objects to the collection, use the Add or AddRange method.

Notes to Inheritors

When overriding Clear in a derived class, be sure to call the Clear method of the base class to guarantee that all the shapes are removed from the collection.

Examples

The following example demonstrates how to use the Clear method to remove the whole collection of shapes from a parent container. This example requires that you have at least two OvalShape controls on a form.

Private Sub Form1_Click() Handles Me.Click
    ' Call the method to remove the shapes.
    RemoveShapes(OvalShape1)
End Sub 

Private Sub RemoveShapes(ByVal shape As Shape)
    Dim canvas As ShapeContainer

    ' Find the ShapeContainer in which the shape is located.
    canvas = shape.Parent
    ' Call the Clear method to remove all shapes.
    canvas.Shapes.Clear()
End Sub
private void form1_Click(object sender, System.EventArgs e)
{
    // Call the method to remove the shapes.
    RemoveShapes(ovalShape1);
}

private void RemoveShapes(Shape shape)
{
    ShapeContainer canvas;

    // Find the ShapeContainer in which the shape is located.
    canvas = shape.Parent;
    // Call the Clear method to remove all shapes.
    canvas.Shapes.Clear();
}

.NET Framework Security

See Also

Reference

ShapeCollection 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)