ToolBar.ToolBarButtonCollection.Item[] 属性

定义

获取或设置集合中的 ToolBarButtonGets or sets a ToolBarButton within the collection.

重载

Item[String]

从集合中获取具有指定键的 ToolBarButtonGets a ToolBarButton with the specified key from the collection.

Item[Int32]

获取或设置工具栏按钮集合中指定索引位置的工具栏按钮。Gets or sets the toolbar button at the specified indexed location in the toolbar button collection.

Item[String]

从集合中获取具有指定键的 ToolBarButtonGets a ToolBarButton with the specified key from the collection.

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 的名称。The name of the ToolBarButton to retrieve.

属性值

ToolBarButton

ToolBarButton,其 Name 属性与指定键匹配。The ToolBarButton whose Name property matches the specified key.

注解

Name属性对应于中的的键 ToolBarButton ToolBar.ToolBarButtonCollectionThe Name property corresponds to the key for a ToolBarButton in the ToolBar.ToolBarButtonCollection.

密钥比较不区分大小写。The key comparison is not case-sensitive. 如果 key 参数为 null 或空字符串,则 Item[] 返回 nullIf the key parameter is null or an empty string, Item[] returns null.

适用于

Item[Int32]

获取或设置工具栏按钮集合中指定索引位置的工具栏按钮。Gets or sets the toolbar button at the specified indexed location in the toolbar button collection.

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 的索引位置。The indexed location of the ToolBarButton in the collection.

属性值

ToolBarButton

ToolBarButton,它表示指定索引位置的工具栏按钮。A ToolBarButton that represents the toolbar button at the specified indexed location.

例外

index 值为 nullThe index value is null.

index 值小于零。The index value is less than zero.

- 或 --or- index 值大于集合中的按钮数,并且按钮集合不为 nullThe index value is greater than the number of buttons in the collection, and the collection of buttons is not null.

示例

下面的代码示例将替换工具栏上的最后一个工具栏按钮。The following code example replaces the last toolbar button on a toolbar. 此代码要求 ToolBar 至少 ToolBarButton 创建一个。This code requires that a ToolBar and at least one ToolBarButton have been created. 该示例获取工具栏上的按钮数,并将最后一个按钮替换为新创建的按钮。The example gets the number of buttons on the toolbar and replaces the last button with a newly created one. index Count 因为 ToolBarButton 集合是从零开始的索引,所以被替换的工具栏按钮的值被设置为减一。The index value of the toolbar button being replaced is set to the Count property, minus one, since the ToolBarButton collection is a zero-based index.

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 ,可以引用具有特定索引值的集合对象。To assign ToolBarButton controls to a specific location, or to retrieve them from the ToolBar.ToolBarButtonCollection, you can reference the collection object with a specific index value. 的索引值 ToolBar.ToolBarButtonCollection 是从零开始的索引。The index value of the ToolBar.ToolBarButtonCollection is a zero-based index.

另请参阅

适用于