ControlCollection.IndexOf 方法 (Object)
在 ControlCollection 執行個體中搜尋指定的控制項,並傳回第一次出現的位置索引 (以零起始)。
命名空間: Microsoft.Office.Tools.Word
組件: Microsoft.Office.Tools.Word (在 Microsoft.Office.Tools.Word.dll 中)
語法
'宣告
Function IndexOf ( _
control As Object _
) As Integer
int IndexOf(
Object control
)
參數
- control
型別:System.Object
要尋找其索引的控制項。
傳回值
型別:System.Int32
控制項的索引,或如果控制項不是在 ControlCollection 執行個體中則為 -1。
範例
下列程式碼範例加入 Button 控制項至文件的起始處,然後會在訊息方塊中顯示按鈕的索引。
Private Sub WordControlIndexOf()
Me.Paragraphs(1).Range.InsertParagraphBefore()
Dim Button1 As Microsoft.Office.Tools.Word.Controls.Button _
= Me.Controls.AddButton(0, 0, 56.25F, 17.25F, "Button1")
Button1.Text = "OK"
If Me.Controls.Contains(Button1) Then
MessageBox.Show("The index of Button1 is " _
& Controls.IndexOf(Button1))
End If
End Sub
private void WordControlIndexOf()
{
this.Paragraphs[1].Range.InsertParagraphBefore();
Microsoft.Office.Tools.Word.Controls.Button button1 =
this.Controls.AddButton(0, 0, 56.25F, 17.25F,
"button1");
button1.Text = "OK";
if (this.Controls.Contains(button1))
{
MessageBox.Show("The index of button1 is " +
Controls.IndexOf(button1));
}
}
.NET Framework 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。