ShapeCollection 類別
表示 Shape 物件的集合。
繼承階層架構
System.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 | 取得ShapeContainer擁有ShapeCollection。 |
回頁首
方法
名稱 | 說明 | |
---|---|---|
![]() |
Add | 將指定的 Shape 加入至 ShapeCollection。 |
![]() |
AddRange | 將陣列的Shape物件到ShapeCollection。 |
![]() |
Clear | 從集合中移除所有的圖形。 |
![]() |
Contains | 決定是否指定Shape成員的集合。 |
![]() |
ContainsKey | 判斷 ShapeCollection 是否包含具有指定索引鍵的項目。 |
![]() |
CopyTo | 複製整個ShapeCollection到一維相容Array,目的陣列的指定索引處開始。 |
![]() |
Dispose | 釋放由 ShapeCollection 使用的 Unmanaged 資源。 |
![]() |
Equals | 判斷指定的物件是否等於目前物件。 (繼承自 Object)。 |
![]() |
GetChildIndex(Shape) | 擷取指定的索引Shape在ShapeCollection。 |
![]() |
GetChildIndex(Shape, Boolean) | 擷取指定的索引Shape在ShapeCollection,並選擇性地引發例外狀況,如果指定的Shape並不在ShapeCollection。 |
![]() |
GetEnumerator | 擷取用來反覆查看 ShapeCollection 之列舉值物件的參考。 |
![]() |
GetHashCode | 做為特定型別的雜湊函式。 (繼承自 Object)。 |
![]() |
GetType | 取得目前執行個體的 Type。 (繼承自 Object)。 |
![]() |
IndexOf | 擷取指定的索引Shape在ShapeCollection。 |
![]() |
IndexOfKey | 擷取指定的項目集合中的第一個項目之索引。 |
![]() |
Remove | 將指定的 Shape 從 ShapeCollection 中移除。 |
![]() |
RemoveAt | 移除Shape的ShapeCollection在指定索引位置。 |
![]() |
SetChildIndex | 設定指定的索引Shape在ShapeCollection到指定的索引值。 |
![]() |
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方法。
範例
下列程式碼範例中移除Shape的ShapeCollection的形式,如果它是集合的成員。這個範例要求您必須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)
HOW TO:使用 LineShape 控制項繪製線條 (Visual Studio)
HOW TO:使用 OvalShape 和 RectangleShape 控制項繪製圖案 (Visual Studio)