Export (0) Print
Expand All

ShapeContainer Class

Provides a container for LineShape, OvalShape, RectangleShape controls, and for any other control that derives from Shape.

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

[BrowsableAttribute(false)]
public sealed class ShapeContainer : UserControl

A LineShape, OvalShape, or RectangleShape control can be contained only in a ShapeContainer object, which acts as a canvas for line and shape controls.

When you add a line or shape to a form or container at design time, a ShapeContainer is automatically created if one does not already exist. The Parent property of the line or shape is set to that ShapeContainer. The Parent property of the ShapeContainer is set to the form or container control to which the line or shape was added.

When you create a line or shape at run time by using the New method, the control's Parent property must be set to a ShapeContainer. If a ShapeContainer already exists for the form or container, you should set the Parent property to that ShapeContainer. If no ShapeContainer exists, you can create a ShapeContainer by using the New method and set its Parent property to the form or container.

Note:

Be careful that you do not create more than one ShapeContainer for each form or container; doing this may introduce unexpected behavior. If you add a design-time line or shape control to a form or container after you write code to create one programmatically, you should modify that code to use the ShapeContainer created by the designer.

The following example checks for an existing ShapeContainer and sets the Parent property of an OvalShape control created at run time by using the New method.

Private Sub Form1_Load(ByVal sender As System.Object, _
  ByVal e As System.EventArgs) Handles MyBase.Load
    Dim NewOval As New OvalShape
    Dim i As Integer
    Dim found As Boolean
    ' Loop through the Controls collection.
    For i = 0 To Me.Controls.Count - 1
        ' If a ShapeContainer is found, make it the parent.
        If TypeOf Controls.Item(i) Is ShapeContainer Then
            NewOval.Parent = Controls.Item(i)
            found = True
            Exit For
        End If
    Next
    ' If no ShapeContainer is found, create one and set the parents.
    If found = False Then
        Dim sc As New ShapeContainer
        sc.Parent = Me
        NewOval.Parent = sc
    End If
    NewOval.Size = New Size(200, 300)
End Sub

System.Object
  System.MarshalByRefObject
    System.ComponentModel.Component
      System.Windows.Forms.Control
        System.Windows.Forms.ScrollableControl
          System.Windows.Forms.ContainerControl
            System.Windows.Forms.UserControl
              Microsoft.VisualBasic.PowerPacks.ShapeContainer

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Community Additions

ADD
Show:
© 2015 Microsoft