ToolBar.ToolBarButtonCollection.IndexOf メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > ToolBar.ToolBarButtonCollection.IndexOf メソッドの意味・解説 

ToolBar.ToolBarButtonCollection.IndexOf メソッド

コレクション内の指定したツール バー ボタンインデックス取得します

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public Function IndexOf ( _
    button As ToolBarButton _
) As Integer
Dim instance As ToolBarButtonCollection
Dim button As ToolBarButton
Dim returnValue As Integer

returnValue = instance.IndexOf(button)
public int IndexOf (
    ToolBarButton button
)
public:
int IndexOf (
    ToolBarButton^ button
)
public int IndexOf (
    ToolBarButton button
)
public function IndexOf (
    button : ToolBarButton
) : int

パラメータ

button

コレクションで検索する ToolBarButton。

戻り値
項目がコレクション存在する場合は、その項目の 0 から始まるインデックスそれ以外場合は -1。

解説解説

このメソッドにより、簡単にコレクション内の ToolBarButtonインデックス値にアクセスできますインデックス値を使用すると、ToolBar でどの ToolBarButtonクリックする簡単に決定できますクリックされた ToolBarButton は、ToolBarButtonClickEventArgs.Button プロパティIndexOf 値を評価することにより決定されます。

使用例使用例

ToolBar3 つの ToolBarButton コントロール作成するコード例次に示しますツール バー ボタンボタン コレクション割り当てられコレクションツール バー割り当てられツール バーフォーム追加されます。ツール バーの ButtonClick イベント発生すると、ToolBarButtonClickEventArgs の Button プロパティ評価され該当するダイアログ ボックス開きます。このコードは、Form、OpenFileDialog、SaveFileDialog、および PrintDialog がすべて作成されていることを前提にしています。

Public Sub InitializeMyToolBar()
    ' Create and initialize the ToolBar and ToolBarButton controls.
    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 event-handler delegate.
    AddHandler toolBar1.ButtonClick, AddressOf
 toolBar1_ButtonClick
    
    ' Add the ToolBar to the Form.
    Controls.Add(toolBar1)
End Sub    

Private Sub toolBar1_ButtonClick(ByVal
 sender As Object, _
ByVal e As ToolBarButtonClickEventArgs)

    ' Evaluate the Button property to determine which button was clicked.
    Select Case toolBar1.Buttons.IndexOf(e.Button)
        Case 0
            openFileDialog1.ShowDialog()
            ' Insert additional code here to open the file.
        Case 1
            saveFileDialog1.ShowDialog()
            ' Insert additional code here to save the file.
        Case 2
            printDialog1.ShowDialog()
            ' Insert additional code here to print the file.    
    End Select
End Sub

public void InitializeMyToolBar()
 {
    // Create and initialize the ToolBar and ToolBarButton controls.
    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 event-handler delegate.
    toolBar1.ButtonClick += new ToolBarButtonClickEventHandler(
       toolBar1_ButtonClick);
    
    // Add the ToolBar to the Form.
    Controls.Add(toolBar1);
 }
 
 private void toolBar1_ButtonClick (
                         Object sender, 
                         ToolBarButtonClickEventArgs e)
 {
   // Evaluate the Button property to determine which button was clicked.
   switch(toolBar1.Buttons.IndexOf(e.Button))
   {
      case 0:
         openFileDialog1.ShowDialog();
         // Insert additional code here to open the file.
         break; 
      case 1:
         saveFileDialog1.ShowDialog();
         // Insert additional code here to save the file.
         break; 
      case 2:
         printDialog1.ShowDialog();
         // Insert additional code here to print the file.    
         break; 
    }
 }

public:
   void InitializeMyToolBar()
   {
      // Create and initialize the ToolBar and ToolBarButton controls.
      toolBar1 = gcnew ToolBar;
      ToolBarButton^ toolBarButton1 = gcnew ToolBarButton;
      ToolBarButton^ toolBarButton2 = gcnew ToolBarButton;
      ToolBarButton^ toolBarButton3 = gcnew 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 event-handler delegate.
      toolBar1->ButtonClick += gcnew ToolBarButtonClickEventHandler(
         this, &Form1::toolBar1_ButtonClick );
      
      // Add the ToolBar to the Form.
      Controls->Add( toolBar1 );
   }

private:
   void toolBar1_ButtonClick(
      Object^ sender,
      ToolBarButtonClickEventArgs^ e )
   {
      // Evaluate the Button property to determine which button was
 clicked.
      switch ( toolBar1->Buttons->IndexOf( e->Button
 ) )
      {
         case 0:
            openFileDialog1->ShowDialog();
            // Insert additional code here to open the file.
            break;
         case 1:
            saveFileDialog1->ShowDialog();
            // Insert additional code here to save the file.
            break;
         case 2:
            printDialog1->ShowDialog();
            // Insert additional code here to print the file.    
            break;
      }
   }
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ToolBar.ToolBarButtonCollection クラス
ToolBar.ToolBarButtonCollection メンバ
System.Windows.Forms 名前空間
ToolBarButtonClickEventArgs


このページでは「.NET Framework クラス ライブラリ リファレンス」からToolBar.ToolBarButtonCollection.IndexOf メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からToolBar.ToolBarButtonCollection.IndexOf メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からToolBar.ToolBarButtonCollection.IndexOf メソッド を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

ToolBar.ToolBarButtonCollection.IndexOf メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ToolBar.ToolBarButtonCollection.IndexOf メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS