Share via


RectangleShape Constructor (ShapeContainer)

Initializes a new instance of the RectangleShape class, specifying the ShapeContainer that will contain it.

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

Syntax

'Declaration
Public Sub New ( _
    parent As ShapeContainer _
)
public RectangleShape(
    ShapeContainer parent
)
public:
RectangleShape(
    ShapeContainer^ parent
)
new : 
        parent:ShapeContainer -> RectangleShape
public function RectangleShape(
    parent : ShapeContainer
)

Parameters

Remarks

A RectangleShape control cannot be displayed directly on a form or container control; it must be contained in a ShapeContainer object. After you initialize a RectangleShape, you will have to set its Parent property either to an existing ShapeContainer or to a new instance of ShapeContainer.

When you add a RectangleShape to a form or container that already contains a ShapeContainer, you should use the existing ShapeContainer instead of declaring a new one. Hosting more than one ShapeContainer on a form or container can cause unexpected results with z-order and events.

Examples

The following example creates a RectangleShape and adds it to a form that already contains a LineShape. This example requires that you have a LineShape named LineShape1 on a form.

Private Sub DrawRectangle2()
    ' Declare a RectangleShape and parent it to  
    ' LineShape1's ShapeContainer. 
    Dim rect1 As New Microsoft.VisualBasic.PowerPacks.
        RectangleShape(LineShape1.Parent)
    ' Set the location and size of the rectangle.
    rect1.Left = 40
    rect1.Top = 40
    rect1.Width = 120
    rect1.Height = 220
End Sub
private void DrawRectangle2()
{
    // Declare a RectangleShape and parent it to  
    // lineShape1's ShapeContainer.
    Microsoft.VisualBasic.PowerPacks.RectangleShape rect1 = 
        new Microsoft.VisualBasic.PowerPacks.RectangleShape(lineShape1.Parent);
    // Set the location and size of the rectangle.
    rect1.Left = 40;
    rect1.Top = 40;
    rect1.Width = 120;
    rect1.Height = 220;
}

.NET Framework Security

See Also

Reference

RectangleShape Class

RectangleShape Overload

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)