ToolBar.ToolBarButtonCollection.Count Свойство

Определение

Получает число кнопок в коллекции кнопок панели инструментов.

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, назначенных данной панели инструментов.

Реализации

Атрибуты

Примеры

В следующем примере кода отображается CountButtons до и после Clear вызова метода . Для этого кода требуется, чтобы был создан по крайней 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 в качестве верхних границ цикла для итерации коллекции. Значение индекса коллекции является отсчитываемым от нуля индексом, поэтому необходимо вычесть его из переменной цикла, в противном случае вы превысите верхние границы коллекции и вызовете исключение.

Применяется к

См. также раздел