次の方法で共有


ShapeContainer.Shapes プロパティ

ShapeContainer に含まれる図形のコレクションを取得します。

名前空間:  Microsoft.VisualBasic.PowerPacks
アセンブリ:  Microsoft.VisualBasic.PowerPacks.Vs (Microsoft.VisualBasic.PowerPacks.Vs.dll 内)

構文

'宣言
<BrowsableAttribute(False)> _
Public ReadOnly Property Shapes As ShapeCollection
[BrowsableAttribute(false)]
public ShapeCollection Shapes { get; }
[BrowsableAttribute(false)]
public:
property ShapeCollection^ Shapes {
    ShapeCollection^ get ();
}
[<BrowsableAttribute(false)>]
member Shapes : ShapeCollection with get
function get Shapes () : ShapeCollection

プロパティ値

型 : Microsoft.VisualBasic.PowerPacks.ShapeCollection
ShapeContainer に含まれる図形のコレクションを表す ShapeCollection

解説

ShapeCollection は図形のコレクションに親として機能します。 たとえば、複数の図形が Formに追加されると、各図形はフォームの ShapeContainer に割り当てられた ShapeCollection のメンバーです。

ShapeCollection クラスで使用できるメソッドを使用して ShapeContainer に割り当てられた ShapeCollection の図形を使用できます。

ShapeContainer内に図形を追加する場合は、追加するように図形を初期化する前に SuspendLayout のメソッドを呼び出すことをお勧めします。 ShapeContainerに図形を追加したら、ResumeLayout のメソッドを呼び出します。 SuspendLayoutResumeLayout を使用して複数の形状を持つアプリケーションのパフォーマンスが向上します。

次の例では、フォームの ShapeCollection から、コレクションのメンバーである場合 Shape (Shapes のプロパティで表される)。 この例では、フォームの LineShapeOvalShapeRectangleShape のコントロールが必要です。 図形をクリックすると、コレクションの最後の図形である 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);
        }
    }
}

.NET Framework セキュリティ

  • 直前の呼び出し元に対する完全な信頼。このメンバーは、部分的に信頼されているコードから使用することはできません。詳細については、「部分信頼コードからのライブラリの使用」を参照してください。

参照

関連項目

ShapeContainer クラス

Microsoft.VisualBasic.PowerPacks 名前空間

その他の技術情報

ライン コントロールとシェイプ コントロールの概要 (Visual Studio)

方法 : LineShape コントロールを使用して線を描画する (Visual Studio)

方法 : OvalShape コントロールおよび RectangleShape コントロールを使用して図形を描画する (Visual Studio)