共用方式為


ShapeCollection.Remove 方法

將指定的 ShapeShapeCollection 移除。

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

語法

'宣告
Public Sub Remove ( _
    value As Shape _
)
public void Remove(
    Shape value
)
public:
void Remove(
    Shape^ value
)
member Remove : 
        value:Shape -> unit
public function Remove(
    value : Shape
)

參數

備註

Shape 控制項從集合中移除時,後續的所有圖案都會在集合中上移一個位置。

使用 RemoveAt 方法,您也可以移除 Shape ,使用 Clear 方法,或是移除所有的形狀。

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

繼承者注意事項

覆寫衍生類別中 Remove ,請確定呼叫基底類別的 Remove 以確保形狀已從集合中移除。

範例

如果是表單之 ShapeCollection的成員,下列範例示範如何使用 Remove 方法從表單中移除 Shape 。 這個範例要求您的表單上必須有至少兩個 OvalShape 控制項。

Private Sub Form1_Click() Handles Me.Click
    Dim canvas As ShapeContainer
    ' Get the ShapeContainer.
    canvas = OvalShape1.Parent
    ' If OvalShape2 is in the same collection, remove it. 
    If canvas.Shapes.Contains(OvalShape2) Then
        canvas.Shapes.Remove(OvalShape2)
    End If 
End Sub
private void form1_Click(object sender, System.EventArgs e)
{
    ShapeContainer canvas;
    // Get the ShapeContainer.
    canvas = ovalShape1.Parent;
    // If OvalShape2 is in the same collection, remove it. 
    if (canvas.Shapes.Contains(ovalShape2))
    {
        canvas.Shapes.Remove(ovalShape2);
    }
}

.NET Framework 安全性

請參閱

參考

ShapeCollection 類別

Microsoft.VisualBasic.PowerPacks 命名空間

其他資源

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

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

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