ShapeCollection.ContainsKey Method
Determines whether the ShapeCollection contains an item with the specified key.
Namespace: Microsoft.VisualBasic.PowerPacks
Assembly: Microsoft.VisualBasic.PowerPacks.Vs (in Microsoft.VisualBasic.PowerPacks.Vs.dll)
Syntax
'Declaration
Public Function ContainsKey ( _
key As String _
) As Boolean
public bool ContainsKey(
string key
)
public:
bool ContainsKey(
String^ key
)
member ContainsKey :
key:string -> bool
public function ContainsKey(
key : String
) : boolean
Parameters
key
Type: System.StringThe key to locate in the ShapeCollection.
Return Value
Type: System.Boolean
true if the ShapeCollection contains an item with the specified key; otherwise, false.
Remarks
The Name property of a Shape is the same as the key for a Shape in the ShapeCollection.
Examples
The following example demonstrates how to use the ContainsKey method to remove a Shape from a form if it is a member of the form's ShapeCollection. This example requires that you have at least two OvalShape controls on a form.
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.ContainsKey("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.ContainsKey("ovalShape2"))
{
canvas.Shapes.Remove(ovalShape2);
}
}
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.
See Also
Reference
Microsoft.VisualBasic.PowerPacks Namespace
Other Resources
Introduction to the Line and Shape Controls (Visual Studio)
How to: Draw Lines with the LineShape Control (Visual Studio)
How to: Draw Shapes with the OvalShape and RectangleShape Controls (Visual Studio)