ToolBar.ToolBarButtonCollection.Count 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得工具列按鈕集合中的按鈕數量。
public:
property int Count { int get(); };
[System.ComponentModel.Browsable(false)]
public int Count { get; }
[<System.ComponentModel.Browsable(false)>]
member this.Count : int
Public ReadOnly Property Count As Integer
屬性值
分配給工具列的控制項編號 ToolBarButton 。
實作
- 屬性
範例
以下程式碼範例顯示方法呼叫前後Clear的 。ButtonsCount 此程式碼要求 ToolBar 已建立至少一個 ToolBarButton 的 。
public:
void ClearMyToolBar()
{
int btns;
// Get the count before the Clear method is called.
btns = toolBar1->Buttons->Count;
toolBar1->Buttons->Clear();
MessageBox::Show( "Count Before Clear: " + btns.ToString() +
"\nCount After Clear: " + toolBar1->Buttons->Count.ToString() );
}
public void ClearMyToolBar()
{
int btns;
// Get the count before the Clear method is called.
btns = toolBar1.Buttons.Count;
toolBar1.Buttons.Clear();
MessageBox.Show("Count Before Clear: " + btns.ToString() +
"\nCount After Clear: " + toolBar1.Buttons.Count.ToString());
}
Public Sub ClearMyToolBar()
Dim btns As Integer
' Get the count before the Clear method is called.
btns = toolBar1.Buttons.Count
toolBar1.Buttons.Clear()
MessageBox.Show("Count Before Clear: " + btns.ToString() & _
Microsoft.VisualBasic.ControlChars.Cr & "Count After Clear: " & _
toolBar1.Buttons.Count.ToString())
End Sub
備註
屬性 Count 會記錄實際分配給集合的控制項數量 ToolBarButton 。 通常會將 Count 屬性值作為迴圈的上界來遍歷集合。 集合的索引值是以零為基礎,因此你必須從迴圈變數中減去一,否則會超過集合的上限並拋出例外。