Share via


ShapeCollection.Contains Method

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

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

Syntax

'Declaration
Public Function Contains ( _
    value As Shape _
) As Boolean
'Usage
Dim instance As ShapeCollection 
Dim value As Shape 
Dim returnValue As Boolean 

returnValue = instance.Contains(value)
public bool Contains(
    Shape value
)
public:
bool Contains(
    Shape^ value
)
public function Contains(
    value : Shape
) : boolean

Parameters

Return Value

Type: System.Boolean
true if the Shape is a member of the collection; otherwise, false.

Remarks

This method enables you to determine whether a Shape is a member of the collection before you try to perform operations on the Shape. You can use this method to confirm that a Shape has been added to or is still a member of the collection.

Examples

The following example demonstrates how to use the Contains method to remove a Shape from a form if it is a member of the form's ShapeCollection. This example requires that you have at least two OvalShape controls on a form.

Private Sub Form1_Click(ByVal sender As Object, _
 ByVal e As System.EventArgs) Handles Me.Click
    Dim canvas As ShapeContainer
    ' Get the ShapeContainer.
    canvas = OvalShape1.Parent
    ' If OvalShape2 is in the same collection, remove it. 
    If canvas.Shapes.Contains(OvalShape2) Then
        canvas.Shapes.Remove(OvalShape2)
    End If 
End Sub
private void form1_Click(object sender, System.EventArgs e)
{
    ShapeContainer canvas;
    // Get the ShapeContainer.
    canvas = ovalShape1.Parent;
    // If OvalShape2 is in the same collection, remove it. 
    if (canvas.Shapes.Contains(ovalShape2))
    {
        canvas.Shapes.Remove(ovalShape2);
    }
}

.NET Framework Security

See Also

Reference

ShapeCollection Class

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)