共用方式為


ShapeCollection.Clear 方法

移除集合中的所有圖案。

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

語法

'宣告
Public Sub Clear
public void Clear()
public:
virtual void Clear() sealed
abstract Clear : unit -> unit  
override Clear : unit -> unit
public final function Clear()

實作

IList.Clear

備註

您可以使用 Clear 方法從 ShapeContainer中移除整個形狀集合。

若要從集合中移除個別形狀,請使用 RemoveRemoveAt 方法。

將新的 Shape 物件加入集合,請使用 AddAddRange 方法。

繼承者注意事項

覆寫衍生類別中 Clear ,請確定呼叫基底類別的 Clear 方法會確保所有圖案從集合中移除。

範例

下列範例示範如何使用 Clear 方法從父容器移除整個形狀集合。 這個範例要求您的表單上必須有至少兩個 OvalShape 控制項。

Private Sub Form1_Click() Handles Me.Click
    ' Call the method to remove the shapes.
    RemoveShapes(OvalShape1)
End Sub 

Private Sub RemoveShapes(ByVal shape As Shape)
    Dim canvas As ShapeContainer

    ' Find the ShapeContainer in which the shape is located.
    canvas = shape.Parent
    ' Call the Clear method to remove all shapes.
    canvas.Shapes.Clear()
End Sub
private void form1_Click(object sender, System.EventArgs e)
{
    // Call the method to remove the shapes.
    RemoveShapes(ovalShape1);
}

private void RemoveShapes(Shape shape)
{
    ShapeContainer canvas;

    // Find the ShapeContainer in which the shape is located.
    canvas = shape.Parent;
    // Call the Clear method to remove all shapes.
    canvas.Shapes.Clear();
}

.NET Framework 安全性

請參閱

參考

ShapeCollection 類別

Microsoft.VisualBasic.PowerPacks 命名空間

其他資源

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

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

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