ShapeCollection.SetChildIndex 方法
將 ShapeCollection 中指定之 Shape 的索引,設定為指定的索引值。
命名空間: Microsoft.VisualBasic.PowerPacks
組件: Microsoft.VisualBasic.PowerPacks.Vs (在 Microsoft.VisualBasic.PowerPacks.Vs.dll 中)
語法
'宣告
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
)
參數
child
類型:Microsoft.VisualBasic.PowerPacks.Shape要搜尋的 Shape。
newIndex
類型:Int32Shape 的新索引值。
例外狀況
例外狀況 | 條件 |
---|---|
ArgumentException | child 圖案不在 ShapeCollection 中。 |
備註
當呼叫 SetChildIndex 時, child 參數所參考的 Shape 移至 newIndex指定的位置。 在 ShapeCollection 的其他 Shape 參考重新排列允許移動。
範例
下列範例示範如何使用 SetChildIndex 方法變更 Shape 在 ShapeCollection中的索引。 這個範例要求您的表單上必須有至少兩個 OvalShape 控制項。
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 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。
請參閱
參考
Microsoft.VisualBasic.PowerPacks 命名空間
其他資源
Line 和 Shape 控制項簡介 (Visual Studio)