ToolBar.ToolBarButtonCollection.Item[] 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
在集合中取得或設定 。ToolBarButton
多載
| 名稱 | Description |
|---|---|
| Item[String] |
從集合中取得指定金鑰的 a ToolBarButton 。 |
| Item[Int32] |
在工具列按鈕集合中指定索引位置取得或設定工具列按鈕。 |
Item[String]
從集合中取得指定金鑰的 a 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 名稱。
屬性值
其ToolBarButtonName屬性與指定的鍵相符。
備註
該Name性質對應於 中 a 的ToolBarButtonToolBar.ToolBarButtonCollection鍵。
關鍵比較並不區分大小寫。 若 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 工具列按鈕在指定索引位置。
例外狀況
index 值是 null。
範例
以下程式碼範例取代了工具列的最後一個按鈕。 此程式碼要求至少建立 a ToolBar 和 一個 ToolBarButton 。 範例中會取得工具列上的按鈕數量,並將最後一個按鈕替換成新建立的按鈕。
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 索引值為零為基礎的索引。