Share via


ShapeCollection.SetChildIndex Method (Shape, Int32)

 

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

public void SetChildIndex(
    Shape child,
    int newIndex
)
public:
void SetChildIndex(
    Shape^ child,
    int newIndex
)
member SetChildIndex : 
        child:Shape *
        newIndex:int -> unit
Public Sub SetChildIndex (
    child As Shape,
    newIndex As Integer
)

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 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);
    }
}
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

See Also

ShapeCollection Class
Microsoft.VisualBasic.PowerPacks Namespace
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)

Return to top