ツール バー ボタン コレクション内のボタンの数を取得します。
Public Overridable ReadOnly Property Count As Integer Implements _ ICollection.Count
[C#]
public virtual int Count {get;}
[C++]
public: __property virtual int get_Count();
[JScript]
public function get Count() : int;
プロパティ値
ツール バーに割り当てられた ToolBarButton コントロールの数。
実装
解説
Count プロパティは、コレクションに割り当てられている ToolBarButton コントロールの実際の数を保持します。通常は、コレクションを反復処理するときに、ループの上限として Count プロパティ値を使用します。コレクションのインデックス値は 0 から始まります。したがって、ループ変数から 1 を引く必要があります。そうしないと、コレクションの上限値を超えて、例外がスローされます。
使用例
[Visual Basic, C#, C++] Clear メソッドが呼び出される前後に Buttons の Count を表示する例を次に示します。このコードは、少なくとも 1 つの ToolBarButton を持つ ToolBar が作成されていることを前提にしています。
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
[C#]
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());
}
[C++]
public:
void ClearMyToolBar()
{
int btns;
// Get the count before the Clear method is called.
btns = toolBar1->Buttons->Count;
toolBar1->Buttons->Clear();
MessageBox::Show(String::Format( S"Count Before Clear: {0}\nCount After Clear: {1}",
__box(btns), __box(toolBar1->Buttons->Count)));
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET
参照
ToolBar.ToolBarButtonCollection クラス | ToolBar.ToolBarButtonCollection メンバ | System.Windows.Forms 名前空間 | ToolBarButton