Share via


ShapeCollection.Add Method

Adds the specified Shape to the ShapeCollection.

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

Syntax

'Declaration
Public Sub Add ( _
    value As Shape _
)
'Usage
Dim instance As ShapeCollection 
Dim value As Shape

instance.Add(value)
public void Add(
    Shape value
)
public:
void Add(
    Shape^ value
)
public function Add(
    value : Shape
)

Parameters

Remarks

The Add method enables you to add Shape objects to the end of a ShapeCollection.

You can also add new Shape objects to the collection by using the AddRange method.

To remove a Shape that you previously added, use the Remove, RemoveAt, or Clear method.

Notes to Inheritors:

When overriding Add in a derived class, be sure to call the Add method of the base class to guarantee that the Shape is added to the ShapeCollection.

Examples

The following example adds a new Shape to the ShapeCollection of a form. This example requires that you have a RectangleShape control on a form.

Private Sub RectangleShape1_Click(ByVal sender As System.Object, _
 ByVal e As System.EventArgs) Handles RectangleShape1.Click
    ' Declare a new oval shape to add to the form. 
    Dim oval As OvalShape = New OvalShape()
    ' Add the oval shape to the form.
    RectangleShape1.Parent.Shapes.Add(oval)
    oval.Location = New Point(50, 50)
    oval.Size = New Size(200, 100)
End Sub
private void rectangleShape1_Click(System.Object sender, System.EventArgs e)
{
    // Declare a new oval shape to add to the form.
    OvalShape oval = new OvalShape();
    // Add the oval shape to the form.
    rectangleShape1.Parent.Shapes.Add(oval);
    oval.Location = new Point(50, 50);
    oval.Size = new Size(200, 100);
}

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