共用方式為


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)

HOW TO:使用 LineShape 控制項繪製線條 (Visual Studio)

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