ツール バー ボタン コレクション内の指定したインデックス位置にあるツール バー ボタンを取得または設定します。
[C#] C# では、このプロパティは ToolBar.ToolBarButtonCollection クラスのインデクサになります。
Public Overridable Default Property Item( _
ByVal index As Integer _) As ToolBarButton
[C#]
public virtual ToolBarButton this[intindex] {get; set;}
[C++]
public: __property virtual ToolBarButton* get_Item(intindex);public: __property virtual void set_Item(intindex, ToolBarButton*);
[JScript]
returnValue = ToolBarButtonCollectionObject.Item(index);ToolBarButtonCollectionObject.Item(index) = returnValue;またはreturnValue = ToolBarButtonCollectionObject(index);ToolBarButtonCollectionObject(index) = returnValue;
[JScript] JScript では、この型で定義されている既定のインデックス プロパティを使用することができます。しかし、独自のインデックス プロパティを明示的に定義することはできません。ただし、このクラスの expando 属性を指定すると、既定のインデックス プロパティが提供されます。提供されるインデックス プロパティの型は Object 型であり、インデックス型は String になります。
引数 [JScript]
- index
コレクション内の ToolBarButton の位置を示すインデックス値。
パラメータ [Visual Basic, C#, C++]
- index
コレクション内の ToolBarButton の位置を示すインデックス値。
プロパティ値
指定したインデックス位置にあるツール バー ボタンを表す ToolBarButton 。
例外
| 例外の種類 | 条件 |
|---|---|
| ArgumentNullException | index 値は null 参照 (Visual Basic では Nothing) です。 |
| ArgumentOutOfRangeException | index 値が 0 未満です。
または index 値がコレクション内のボタン数を超える値であり、ボタンのコレクションが null 参照 (Visual Basic では Nothing) ではありません。 |
解説
ToolBarButton コントロールを特定の位置に割り当てるか、 ToolBar.ToolBarButtonCollection から取得するには、特定の値を指定してコレクション オブジェクトを参照できます。 ToolBar.ToolBarButtonCollection のインデックス値は 0 から始まります。
使用例
[Visual Basic, C#, C++] ツール バーの最後のツール バー ボタンを置き換える例を次に示します。このコードは、 ToolBar 、および少なくとも 1 つの ToolBarButton が作成されていることを前提にしています。この例では、ツール バーのボタン数を取得し、最後のボタンを新しく作成したボタンに置き換えます。 ToolBarButton コレクションのインデックス値は 0 から始まるため、置き換えられたツール バー ボタンの index 値は Count プロパティの値か、プロパティの値から 1 を引いた値が設定されます。
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
[C#]
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;
}
[C++]
public:
void ReplaceMyToolBarButton()
{
int btns;
btns = toolBar1->Buttons->Count;
ToolBarButton* toolBarButton1 = new ToolBarButton();
toolBarButton1->Text = S"myButton";
// Replace the last ToolBarButton in the collection.
toolBar1->Buttons->Item[btns - 1] = toolBarButton1;
}
[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 ファミリ
参照
ToolBar.ToolBarButtonCollection クラス | ToolBar.ToolBarButtonCollection メンバ | System.Windows.Forms 名前空間 | Count | ToolBarButton