다음을 통해 공유


ShapeCollection 클래스

업데이트: 2007년 11월

Shape 개체의 컬렉션을 나타냅니다.

네임스페이스:  Microsoft.VisualBasic.PowerPacks
어셈블리:  Microsoft.VisualBasic.PowerPacks.Vs(Microsoft.VisualBasic.PowerPacks.Vs.dll)

구문

Public NotInheritable Class ShapeCollection _
    Implements IList, IDisposable

Dim instance As ShapeCollection
public sealed class ShapeCollection : IList, 
    IDisposable
public ref class ShapeCollection sealed : IList, 
    IDisposable
public final class ShapeCollection implements IList, IDisposable

설명

Add, RemoveRemoveAt 메서드를 사용하면 컬렉션에서 개별 도형을 추가 및 제거할 수 있습니다. 또한 AddRange 또는 Clear 메서드를 사용하여 컬렉션의 모든 도형을 추가 및 제거할 수도 있습니다.

도형을 Contains 메서드에 전달하여 Shape가 컬렉션의 멤버인지 확인할 수 있습니다. 컬렉션에 있는 도형의 위치 인덱스 값을 가져오려면 IndexOf 메서드에 도형을 전달합니다. CopyTo 메서드를 호출하면 컬렉션을 배열로 복사할 수 있습니다.

예제

다음 코드 예제에서는 폼의 ShapeCollection에서 컬렉션의 멤버인 Shape를 제거합니다. 이 예제를 실행하려면 폼에 LineShape, OvalShapeRectangleShape 컨트롤이 있어야 합니다. 도형을 클릭하면 도형이 컬렉션의 마지막 도형인 경우를 제외하고 ShapeCollection에서 제거됩니다.

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);
        }
    }
}

상속 계층 구조

System.Object
  Microsoft.VisualBasic.PowerPacks.ShapeCollection

스레드로부터의 안전성

이 형식의 모든 공용 static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

참고 항목

참조

ShapeCollection 멤버

Microsoft.VisualBasic.PowerPacks 네임스페이스

기타 리소스

Line 및 Shape 컨트롤 소개(Visual Studio)

방법: LineShape 컨트롤로 선 그리기(Visual Studio)

방법: OvalShape 및 RectangleShape 컨트롤을 사용하여 도형 그리기(Visual Studio)