共用方式為


ShapeCollection 類別

表示 Shape 物件的集合。

繼承階層架構

Object
  Microsoft.VisualBasic.PowerPacks.ShapeCollection

命名空間:  Microsoft.VisualBasic.PowerPacks
組件:  Microsoft.VisualBasic.PowerPacks.Vs (在 Microsoft.VisualBasic.PowerPacks.Vs.dll 中)

語法

'宣告
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

ShapeCollection 類型會公開下列成員。

建構函式

  名稱 描述
公用方法 ShapeCollection 初始化 ShapeCollection 類別的新執行個體。

回頁首

屬性

  名稱 描述
公用屬性 Count 取得集合中圖案的數目。
公用屬性 IsReadOnly 取得值,指出集合是否為唯讀。
公用屬性 Item 取得集合中指定索引位置的 Shape
公用屬性 Owner 取得擁有 ShapeCollection 的 ShapeContainer

回頁首

方法

  名稱 描述
公用方法 Add 將指定的 Shape 加入至 ShapeCollection。
公用方法 AddRange Shape 物件陣列加入 ShapeCollection 中。
公用方法 Clear 移除集合中的所有圖案。
公用方法 Contains 判斷指定的 Shape 是否為集合的成員。
公用方法 ContainsKey 判斷 ShapeCollection 是否包含具有指定索引鍵的項目。
公用方法 CopyTo 從目的陣列的指定索引開始,複製整個 ShapeCollection 至相容的一維 Array
公用方法 Dispose 釋放由 ShapeCollection 使用的 Unmanaged 資源。
公用方法 Equals 判斷指定的物件是否等於目前的物件。 (繼承自 Object)。
公用方法 GetChildIndex(Shape) 擷取 ShapeCollection 中指定之 Shape 的索引。
公用方法 GetChildIndex(Shape, Boolean) 擷取指定的Shape在ShapeCollection 中的索引,並選擇性地引發例外狀況 (如果指定的Shape不在ShapeCollection)。
公用方法 GetEnumerator 擷取用來反覆查看 ShapeCollection 之列舉值物件的參考。
公用方法 GetHashCode 做為預設雜湊函式。 (繼承自 Object)。
公用方法 GetType 取得目前實例 Type 的屬性。 (繼承自 Object)。
公用方法 IndexOf 擷取 ShapeCollection 中指定之 Shape 的索引。
公用方法 IndexOfKey 擷取集合中指定之項目第一次出現時的所在索引。
公用方法 Remove 將指定的 Shape 從 ShapeCollection 移除。
公用方法 RemoveAt Shape 從位於指定索引位置的 ShapeCollection 移除。
公用方法 SetChildIndex 將 ShapeCollection 中指定之 Shape 的索引,設定為指定的索引值。
公用方法 ToString 傳回代表目前物件的字串。 (繼承自 Object)。

回頁首

明確介面實作

  名稱 描述
明確介面實作私用方法 IList.Add
明確介面實作私用方法 IList.Contains
明確介面實作私用方法 ICollection.CopyTo
明確介面實作私用方法 IList.IndexOf
明確介面實作私用方法 IList.Insert
明確介面實作私用屬性 IList.IsFixedSize
明確介面實作私用屬性 ICollection.IsSynchronized
明確介面實作私用方法 IList.Remove
明確介面實作私用屬性 ICollection.SyncRoot

回頁首

備註

AddRemoveRemoveAt 方法可讓您加入和移除個別的圖案。 您也可以使用 AddRangeClear 方法從集合中加入或移除所有的形狀。

您可以判斷 Shape 是否為集合的成員可以將形狀傳遞至 Contains 方法。 若要取得圖案的位置索引值集合中,請將形狀傳遞至 IndexOf 方法。 您可以將集合複製到陣列 (呼叫 CopyTo 方法。

範例

如果它是集合的成員,下列程式碼範例會從表單的 ShapeCollection 移除 Shape 。 這個範例要求您具有 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);
        }
    }
}

執行緒安全

這個類型的任何 Public static (在 Visual Basic 中為 Shared) 成員都是安全執行緒。不保證任何執行個體成員是安全執行緒。

請參閱

參考

Microsoft.VisualBasic.PowerPacks 命名空間

其他資源

Line 和 Shape 控制項簡介 (Visual Studio)

如何:使用 LineShape 控制項繪製線條 (Visual Studio)

如何:使用 OvalShape 和 RectangleShape 控制項繪製圖案 (Visual Studio)