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 |
回頁首
備註
Add、 Remove和 RemoveAt 方法可讓您加入和移除個別的圖案。 您也可以使用 AddRange 或 Clear 方法從集合中加入或移除所有的形狀。
您可以判斷 Shape 是否為集合的成員可以將形狀傳遞至 Contains 方法。 若要取得圖案的位置索引值集合中,請將形狀傳遞至 IndexOf 方法。 您可以將集合複製到陣列 (呼叫 CopyTo 方法。
範例
如果它是集合的成員,下列程式碼範例會從表單的 ShapeCollection 移除 Shape 。 這個範例要求您具有 LineShape、 OvalShape和 RectangleShape 控制項在表單中。 按下形狀時,會從 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)