ShapeCollection.SetChildIndex Method

Sets the index of the specified Shape in the ShapeCollection to the specified index value.

Namespace:  Microsoft.VisualBasic.PowerPacks
Assembly:  Microsoft.VisualBasic.PowerPacks.Vs (in Microsoft.VisualBasic.PowerPacks.Vs.dll)

Syntax

'Declaração
Public Sub SetChildIndex ( _
    child As Shape, _
    newIndex As Integer _
)
public void SetChildIndex(
    Shape child,
    int newIndex
)
public:
void SetChildIndex(
    Shape^ child, 
    int newIndex
)
member SetChildIndex : 
        child:Shape * 
        newIndex:int -> unit 
public function SetChildIndex(
    child : Shape, 
    newIndex : int
)

Parameters

Exceptions

Exception Condition
ArgumentException

The child shape is not in the ShapeCollection.

Remarks

When SetChildIndex is called, the Shape referred to by the child parameter is moved to the position specified by newIndex. The other Shape references in the ShapeCollection are reordered to allow for the move.

Examples

The following example demonstrates how to use the SetChildIndex method to change the index of a Shape in a ShapeCollection. This example requires that you have at least two OvalShape controls on a form.

Private Sub OvalShape1_Click() Handles OvalShape1.Click
    Dim i As Integer
    ' Find the index for OvalShape2.
    i = OvalShape1.Parent.Shapes.GetChildIndex(OvalShape2, False)
    ' If the shape is not in the collection, display a message.
    If i = -1 Then
        MsgBox("OvalShape2 is not in this collection.")
    Else
        ' Change the index to 0.
        OvalShape1.Parent.Shapes.SetChildIndex(OvalShape2, 0)
    End If
End Sub
private void ovalShape1_Click(System.Object sender, System.EventArgs e)
{
    int i;
    // Find the index for OvalShape2.
    i = ovalShape1.Parent.Shapes.GetChildIndex(ovalShape2, false);
    // If the shape is not in the collection, display a message.
    if (i == -1)
    {
        MessageBox.Show("ovalShape2 is not in this collection.");
    }
    else
    {
        // Change the index to 0.
        ovalShape1.Parent.Shapes.SetChildIndex(ovalShape2, 0);
    }
}

.NET Framework Security

See Also

Reference

ShapeCollection Class

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)