次の方法で共有


ToolBar.ToolBarButtonCollection.Item[] プロパティ

定義

コレクション内の ToolBarButton を取得または設定します。

オーバーロード

名前 説明
Item[String]

指定したキーを持つ ToolBarButton をコレクションから取得します。

Item[Int32]

ツール バー ボタン コレクション内の指定したインデックス位置にあるツール バー ボタンを取得または設定します。

Item[String]

ソース:
ToolBar.ToolBarButtonCollection.cs
ソース:
ToolBar.ToolBarButtonCollection.cs

指定したキーを持つ ToolBarButton をコレクションから取得します。

public:
 virtual property System::Windows::Forms::ToolBarButton ^ default[System::String ^] { System::Windows::Forms::ToolBarButton ^ get(System::String ^ key); };
public virtual System.Windows.Forms.ToolBarButton this[string key] { get; }
member this.Item(string) : System.Windows.Forms.ToolBarButton
Default Public Overridable ReadOnly Property Item(key As String) As ToolBarButton

パラメーター

key
String

取得する ToolBarButton の名前。

プロパティ値

Name プロパティが指定したキーと一致するToolBarButton

注釈

Name プロパティは、ToolBar.ToolBarButtonCollection内のToolBarButtonのキーに対応します。

キーの比較では、大文字と小文字は区別されません。 key パラメーターがnullまたは空の文字列の場合、Item[]nullを返します。

適用対象

Item[Int32]

ソース:
ToolBar.ToolBarButtonCollection.cs
ソース:
ToolBar.ToolBarButtonCollection.cs

ツール バー ボタン コレクション内の指定したインデックス位置にあるツール バー ボタンを取得または設定します。

public:
 virtual property System::Windows::Forms::ToolBarButton ^ default[int] { System::Windows::Forms::ToolBarButton ^ get(int index); void set(int index, System::Windows::Forms::ToolBarButton ^ value); };
public virtual System.Windows.Forms.ToolBarButton this[int index] { get; set; }
member this.Item(int) : System.Windows.Forms.ToolBarButton with get, set
Default Public Overridable Property Item(index As Integer) As ToolBarButton

パラメーター

index
Int32

コレクション内の ToolBarButton のインデックス付き場所。

プロパティ値

指定したインデックス付きの場所にあるツール バー ボタンを表す ToolBarButton

例外

index 値は nullです。

index 値が 0 未満です。

-又は-

index値がコレクション内のボタンの数より大きく、ボタンのコレクションがnullされていません。

次のコード例では、ツール バーの最後のツール バー ボタンを置き換えます。 このコードでは、 ToolBar と少なくとも 1 つの ToolBarButton が作成されている必要があります。 この例では、ツール バーのボタンの数を取得し、最後のボタンを新しく作成したボタンに置き換えます。 ToolBarButton コレクションは 0 から始まるインデックスであるため、置き換えられるツール バー ボタンのindex値は、Count プロパティから 1 を引いた値に設定されます。

void ReplaceMyToolBarButton()
{
   int btns;
   btns = toolBar1->Buttons->Count;
   ToolBarButton^ toolBarButton1 = gcnew ToolBarButton;
   toolBarButton1->Text = "myButton";
   
   // Replace the last ToolBarButton in the collection.
   toolBar1->Buttons[ btns - 1 ] = toolBarButton1;
}
public void ReplaceMyToolBarButton()
 {
    int btns;
    btns = toolBar1.Buttons.Count;
    ToolBarButton toolBarButton1 = new ToolBarButton();
    toolBarButton1.Text = "myButton";
 
    // Replace the last ToolBarButton in the collection.
    toolBar1.Buttons[btns - 1] = toolBarButton1;
 }
Public Sub ReplaceMyToolBarButton()
    Dim btns As Integer
    btns = toolBar1.Buttons.Count
    Dim toolBarButton1 As New ToolBarButton()
    toolBarButton1.Text = "myButton"
    
    ' Replace the last ToolBarButton in the collection.
    toolBar1.Buttons(btns - 1) = toolBarButton1
End Sub

注釈

コントロール ToolBarButton 特定の場所に割り当てるか、 ToolBar.ToolBarButtonCollectionからコントロールを取得するには、特定のインデックス値を持つコレクション オブジェクトを参照できます。 ToolBar.ToolBarButtonCollectionのインデックス値は 0 から始まるインデックスです。

こちらもご覧ください

適用対象