ToolBar.ToolBarButtonCollection.Item[] 屬性

定義

取得或設定集合中的 ToolBarButton

多載

Item[String]

從集合中取得具有指定索引鍵的 ToolBarButton

Item[Int32]

取得或設定在工具列按鈕集合的指定索引處的工具列按鈕。

Item[String]

從集合中取得具有指定索引鍵的 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 的名稱。

屬性值

ToolBarButton

ToolBarButton 屬性符合指定索引鍵的 Name

備註

屬性 Name 會對應至 中的 索引 ToolBar.ToolBarButtonCollectionToolBarButton

索引鍵比較不區分大小寫。 key如果 參數為 null 或空字串,則 Item[]null 回 。

適用於

Item[Int32]

取得或設定在工具列按鈕集合的指定索引處的工具列按鈕。

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

ToolBarButton,表示位在指定索引處的工具列按鈕。

例外狀況

index 值為 null

index 值小於 0。

-或- index 值大於集合中的按鈕數,而且按鈕集合不是 null

範例

下列程式碼範例會取代工具列上的最後一個工具列按鈕。 此程式碼需要至少已建立一 ToolBarToolBarButton 和 。 此範例會取得工具列上的按鈕數目,並將最後一個按鈕取代為新建立的按鈕。 要 index 取代之工具列按鈕的值會設定為 Count 屬性減一,因為 ToolBarButton 集合是以零起始的索引。

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 索引值為以零起始的索引。

另請參閱

適用於