Breyta

Deila með


ToolBar.ToolBarButtonCollection.Item[] Property

Definition

Gets or sets a ToolBarButton within the collection.

Overloads

Item[String]

Gets 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]

Gets 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

Parameters

key
String

The name of the ToolBarButton to retrieve.

Property Value

The ToolBarButton whose Name property matches the specified key.

Remarks

The Name property corresponds to the key for a ToolBarButton in the ToolBar.ToolBarButtonCollection.

The key comparison is not case-sensitive. If the key parameter is null or an empty string, Item[] returns null.

Applies to

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

Parameters

index
Int32

The indexed location of the ToolBarButton in the collection.

Property Value

A ToolBarButton that represents the toolbar button at the specified indexed location.

Exceptions

The index value is null.

The index value is less than zero.

-or-

The index value is greater than the number of buttons in the collection, and the collection of buttons is not null.

Examples

The following code example replaces the last toolbar button on a toolbar. 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. 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

Remarks

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. The index value of the ToolBar.ToolBarButtonCollection is a zero-based index.

See also

Applies to