共用方式為


ShapeCollection.Clear 方法

更新:2007 年 11 月

移除集合中所有的形狀。

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

語法

Public Sub Clear

Dim instance As ShapeCollection

instance.Clear()
public void Clear()
public:
virtual void Clear() sealed
public final function Clear()

實作

IList.Clear()

備註

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

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

若要將新的 Shape 加入至集合,請使用 AddAddRange 方法。

繼承者注意事項

在衍生類別中覆寫 Clear 時,一定要呼叫基底類別的 Clear 方法,以確保所有形狀都已從集合中移除。

範例

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

  Private Sub Form1_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) 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();
}

使用權限

請參閱

參考

ShapeCollection 類別

ShapeCollection 成員

Microsoft.VisualBasic.PowerPacks 命名空間

其他資源

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

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

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