ToolBarButton.ImageIndex 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定指派給按鈕的影像的索引值。
public:
property int ImageIndex { int get(); void set(int value); };
[System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.ImageIndexConverter))]
public int ImageIndex { get; set; }
[<System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.ImageIndexConverter))>]
member this.ImageIndex : int with get, set
Public Property ImageIndex As Integer
屬性值
指派給工具列按鈕的 Image 的索引值。 預設值為 -1。
- 屬性
例外狀況
value
小於 -1。
範例
下列程式碼範例會建立 和 三 ToolBarButton 個 ToolBar 控制項、將按鈕指派給工具列,並設定一些按鈕的通用屬性。 此程式碼需要 MenuItem 已建立 、 ImageListToolTip 和 , Form 且 ImageList 至少已指派一個 Image 。
public:
void InitializeMyToolBar()
{
// Create the ToolBar, ToolBarButton controls, and menus.
ToolBarButton^ toolBarButton1 = gcnew ToolBarButton( "Open" );
ToolBarButton^ toolBarButton2 = gcnew ToolBarButton;
ToolBarButton^ toolBarButton3 = gcnew ToolBarButton;
ToolBar^ toolBar1 = gcnew ToolBar;
MenuItem^ menuItem1 = gcnew MenuItem( "Print" );
array<MenuItem^>^ temp1 = {menuItem1};
System::Windows::Forms::ContextMenu^ contextMenu1 =
gcnew System::Windows::Forms::ContextMenu( temp1 );
// Add the ToolBarButton controls to the ToolBar.
toolBar1->Buttons->Add( toolBarButton1 );
toolBar1->Buttons->Add( toolBarButton2 );
toolBar1->Buttons->Add( toolBarButton3 );
// Assign an ImageList to the ToolBar and show ToolTips.
toolBar1->ImageList = imageList1;
toolBar1->ShowToolTips = true;
/* Assign ImageIndex, ContextMenu, Text, ToolTip, and
Style properties of the ToolBarButton controls. */
toolBarButton2->Style = ToolBarButtonStyle::Separator;
toolBarButton3->Text = "Print";
toolBarButton3->Style = ToolBarButtonStyle::DropDownButton;
toolBarButton3->ToolTipText = "Print";
toolBarButton3->ImageIndex = 0;
toolBarButton3->DropDownMenu = contextMenu1;
// Add the ToolBar to a form.
Controls->Add( toolBar1 );
}
public void InitializeMyToolBar()
{
// Create the ToolBar, ToolBarButton controls, and menus.
ToolBarButton toolBarButton1 = new ToolBarButton("Open");
ToolBarButton toolBarButton2 = new ToolBarButton();
ToolBarButton toolBarButton3 = new ToolBarButton();
ToolBar toolBar1 = new ToolBar();
MenuItem menuItem1 = new MenuItem("Print");
ContextMenu contextMenu1 = new ContextMenu(new MenuItem[]{menuItem1});
// Add the ToolBarButton controls to the ToolBar.
toolBar1.Buttons.Add(toolBarButton1);
toolBar1.Buttons.Add(toolBarButton2);
toolBar1.Buttons.Add(toolBarButton3);
// Assign an ImageList to the ToolBar and show ToolTips.
toolBar1.ImageList = imageList1;
toolBar1.ShowToolTips = true;
/* Assign ImageIndex, ContextMenu, Text, ToolTip, and
Style properties of the ToolBarButton controls. */
toolBarButton2.Style = ToolBarButtonStyle.Separator;
toolBarButton3.Text = "Print";
toolBarButton3.Style = ToolBarButtonStyle.DropDownButton;
toolBarButton3.ToolTipText = "Print";
toolBarButton3.ImageIndex = 0;
toolBarButton3.DropDownMenu = contextMenu1;
// Add the ToolBar to a form.
Controls.Add(toolBar1);
}
Public Sub InitializeMyToolBar()
' Create the ToolBar, ToolBarButton controls, and menus.
Dim toolBarButton1 As New ToolBarButton("Open")
Dim toolBarButton2 As New ToolBarButton()
Dim toolBarButton3 As New ToolBarButton()
Dim toolBar1 As New ToolBar()
Dim menuItem1 As New MenuItem("Print")
Dim contextMenu1 As New ContextMenu(New MenuItem(){menuItem1})
' Add the ToolBarButton controls to the ToolBar.
toolBar1.Buttons.Add(toolBarButton1)
toolBar1.Buttons.Add(toolBarButton2)
toolBar1.Buttons.Add(toolBarButton3)
' Assign an ImageList to the ToolBar and show ToolTips.
toolBar1.ImageList = imageList1
toolBar1.ShowToolTips = True
' Assign ImageIndex, ContextMenu, Text, ToolTip, and
' Style properties of the ToolBarButton controls.
toolBarButton2.Style = ToolBarButtonStyle.Separator
toolBarButton3.Text = "Print"
toolBarButton3.Style = ToolBarButtonStyle.DropDownButton
toolBarButton3.ToolTipText = "Print"
toolBarButton3.ImageIndex = 0
toolBarButton3.DropDownMenu = contextMenu1
' Add the ToolBar to a form.
Controls.Add(toolBar1)
End Sub
備註
值 ImageIndex 會參考指派給父 ToolBar 控制項之 中 ImageList 影像的索引值。
ImageKey 和 ImageIndex 互斥,這表示如果設定其中一個,另一個會設定為不正確值並忽略。 如果您設定 ImageKey 屬性,屬性 ImageIndex 會自動設定為 -1。 或者,如果您設定 ImageIndex 屬性,會自動 ImageKey 將 設定為空字串 (「」) 。