次の方法で共有


ToolBar.Buttons プロパティ

ツール バー コントロールに割り当てられた ToolBarButton コントロールのコレクションを取得します。

Public ReadOnly Property Buttons As ToolBar.ToolBarButtonCollection
[C#]
public ToolBar.ToolBarButtonCollection Buttons {get;}
[C++]
public: __property ToolBar.ToolBarButtonCollection* get_Buttons();
[JScript]
public function get Buttons() : ToolBar.ToolBarButtonCollection;

プロパティ値

ToolBarButton コントロールのコレクションを格納している ToolBar.ToolBarButtonCollection

解説

Buttons プロパティは、ツール バーに割り当てられたすべての ToolBarButton コントロールを格納するために使用される、0 から始まるインデックス番号が付いたコレクションです。このプロパティは読み取り専用であるため、ツール バー ボタンのコレクションを直接割り当てることはできません。ツール バー ボタンは、 ToolBar.ToolBarButtonCollection クラスから継承したメソッドを使用して追加または削除できます。ボタンを個別に追加する場合は Add メソッドを使用し、ボタンを削除する場合は Remove メソッドを使用します。コレクションからすべてのボタンを削除するには、 Clear メソッドを呼び出します。

使用例

[Visual Basic, C#, C++] ToolBar と 3 つの ToolBarButton コントロールを作成および初期化する例を次に示します。ツール バー ボタンはツール バーに割り当てられ、ツール バーはフォームに追加されます。このコードは、 Form が既に作成されていることを前提にしています。

 
Public Sub InitializeMyToolBar()
    ' Create and initialize the ToolBarButton controls and ToolBar.
    Dim toolBar1 As New ToolBar()
    Dim toolBarButton1 As New ToolBarButton()
    Dim toolBarButton2 As New ToolBarButton()
    Dim toolBarButton3 As New ToolBarButton()
    
    ' Set the Text properties of the ToolBarButton controls.
    toolBarButton1.Text = "Open"
    toolBarButton2.Text = "Save"
    toolBarButton3.Text = "Print"
    
    ' Add the ToolBarButton controls to the ToolBar.
    toolBar1.Buttons.Add(toolBarButton1)
    toolBar1.Buttons.Add(toolBarButton2)
    toolBar1.Buttons.Add(toolBarButton3)
    
    ' Add the ToolBar to the Form.
    Controls.Add(toolBar1)
End Sub


[C#] 
public void InitializeMyToolBar()
 {
    // Create and initialize the ToolBarButton controls and ToolBar.
    ToolBar toolBar1 = new ToolBar();
    ToolBarButton toolBarButton1 = new ToolBarButton();
    ToolBarButton toolBarButton2 = new ToolBarButton();
    ToolBarButton toolBarButton3 = new ToolBarButton();
 
    // Set the Text properties of the ToolBarButton controls.
    toolBarButton1.Text = "Open";
    toolBarButton2.Text = "Save";
    toolBarButton3.Text = "Print";
 
    // Add the ToolBarButton controls to the ToolBar.
    toolBar1.Buttons.Add(toolBarButton1);
    toolBar1.Buttons.Add(toolBarButton2);
    toolBar1.Buttons.Add(toolBarButton3);
 
    // Add the ToolBar to the Form.
    Controls.Add(toolBar1);
 }


[C++] 
public:
void InitializeMyToolBar()
 {
    // Create and initialize the ToolBarButton controls and ToolBar.
    ToolBar* toolBar1 = new ToolBar();
    ToolBarButton* toolBarButton1 = new ToolBarButton();
    ToolBarButton* toolBarButton2 = new ToolBarButton();
    ToolBarButton* toolBarButton3 = new ToolBarButton();
 
    // Set the Text properties of the ToolBarButton controls.
    toolBarButton1->Text = S"Open";
    toolBarButton2->Text = S"Save";
    toolBarButton3->Text = S"Print";
 
    // Add the ToolBarButton controls to the ToolBar.
    toolBar1->Buttons->Add(toolBarButton1);
    toolBar1->Buttons->Add(toolBarButton2);
    toolBar1->Buttons->Add(toolBarButton3);
 
    // Add the ToolBar to the Form.
    Controls->Add(toolBar1);
 }

[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 クラス | ToolBar メンバ | System.Windows.Forms 名前空間 | ToolBar.ToolBarButtonCollection