ShapeCollection Class
Represents a collection of Shape objects.
Inheritance Hierarchy
Object
Microsoft.VisualBasic.PowerPacks.ShapeCollection
Namespace: Microsoft.VisualBasic.PowerPacks
Assembly: Microsoft.VisualBasic.PowerPacks.Vs (in Microsoft.VisualBasic.PowerPacks.Vs.dll)
Syntax
'Declaration
Public NotInheritable Class ShapeCollection _
Implements IList, IDisposable
public sealed class ShapeCollection : IList,
IDisposable
public ref class ShapeCollection sealed : IList,
IDisposable
[<Sealed>]
type ShapeCollection =
class
interface IList
interface IDisposable
end
public final class ShapeCollection implements IList, IDisposable
The ShapeCollection type exposes the following members.
Constructors
Name | Description | |
---|---|---|
ShapeCollection | Initializes a new instance of the ShapeCollection class. |
Top
Properties
Name | Description | |
---|---|---|
Count | Gets the number of shapes in the collection. | |
IsReadOnly | Gets a value indicating whether a collection is read-only. | |
Item | Gets the Shape at the specified indexed location in the collection. | |
Owner | Gets the ShapeContainer that owns the ShapeCollection. |
Top
Methods
Name | Description | |
---|---|---|
Add | Adds the specified Shape to the ShapeCollection. | |
AddRange | Adds an array of Shape objects to the ShapeCollection. | |
Clear | Removes all shapes from the collection. | |
Contains | Determines whether the specified Shape is a member of the collection. | |
ContainsKey | Determines whether the ShapeCollection contains an item with the specified key. | |
CopyTo | Copies the whole ShapeCollection to a compatible one-dimensional Array, starting at the specified index of the destination array. | |
Dispose | Releases the unmanaged resources used by the ShapeCollection. | |
Equals | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | |
GetChildIndex(Shape) | Retrieves the index of the specified Shape in the ShapeCollection. | |
GetChildIndex(Shape, Boolean) | Retrieves the index of the specified Shape in the ShapeCollection, and optionally raises an exception if the specified Shape is not in the ShapeCollection. | |
GetEnumerator | Retrieves a reference to an enumerator object that is used to iterate over a ShapeCollection. | |
GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
IndexOf | Retrieves the index of the specified Shape in the ShapeCollection. | |
IndexOfKey | Retrieves the index of the first occurrence of the specified item in the collection. | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
Remove | Removes the specified Shape from the ShapeCollection. | |
RemoveAt | Removes a Shape from the ShapeCollection at the specified indexed location. | |
SetChildIndex | Sets the index of the specified Shape in the ShapeCollection to the specified index value. | |
ToString | Returns a string that represents the current object. (Inherited from Object.) |
Top
Explicit Interface Implementations
Name | Description | |
---|---|---|
IListAdd | ||
IListContains | ||
ICollectionCopyTo | ||
IListIndexOf | ||
IListInsert | ||
IListIsFixedSize | ||
ICollectionIsSynchronized | ||
IListRemove | ||
ICollectionSyncRoot |
Top
Remarks
The Add, Remove, and RemoveAt methods enable you to add and remove individual shapes from the collection. You can also use the AddRange or Clear method to add or remove all the shapes from the collection.
You can determine whether a Shape is a member of the collection by passing the shape into the Contains method. To get the index value of the location of a shape in the collection, pass the shape into the IndexOf method. You can copy the collection into an array by calling the CopyTo method.
Examples
The following code example removes a Shape from the ShapeCollection of a form if it is a member of the collection. The example requires that you have a LineShape, an OvalShape, and a RectangleShape control on a form. When a shape is clicked, it is removed from the ShapeCollection unless it is the last shape in the collection.
Private Sub Shapes_Click(
ByVal sender As System.Object,
ByVal e As System.EventArgs
) Handles RectangleShape1.Click,
OvalShape1.Click, LineShape1.Click
' Determine whether the shape is in the collection.
If ShapeContainer1.Shapes.Contains(sender) Then
' If the Index is greater than 0, remove the shape.
If ShapeContainer1.Shapes.IndexOf(sender) > 0 Then
ShapeContainer1.Shapes.Remove(sender)
End If
End If
End Sub
private void Shapes_Click(System.Object sender, System.EventArgs e)
{
// Determine whether the shape is in the collection.
if (shapeContainer1.Shapes.Contains((Shape)sender))
// If the Index is greater than 0, remove the shape.
{
if (shapeContainer1.Shapes.IndexOf((Shape)sender) > 0)
{
shapeContainer1.Shapes.Remove((Shape)sender);
}
}
}
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See Also
Reference
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)