ToolStripItem.ImageIndex 屬性

定義

取得或設定此項目上顯示的影像索引值。

public:
 property int ImageIndex { int get(); void set(int value); };
[System.ComponentModel.Browsable(false)]
[System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.NoneExcludedImageIndexConverter))]
[System.Windows.Forms.RelatedImageList("Owner.ImageList")]
public int ImageIndex { get; set; }
[<System.ComponentModel.Browsable(false)>]
[<System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.NoneExcludedImageIndexConverter))>]
[<System.Windows.Forms.RelatedImageList("Owner.ImageList")>]
member this.ImageIndex : int with get, set
Public Property ImageIndex As Integer

屬性值

Int32

ImageList 中為項目顯示之影像的以零起始的索引。 預設值為 -1,表示影像清單是空的。

屬性

例外狀況

value 小於 -1。

備註

ImageKeyImageIndex 互斥,這表示如果已設定,另一個設定為不正確值並忽略。 如果您設定 ImageKey 屬性, ImageIndex 則屬性會自動設定為 -1。 或者,如果您設定 ImageIndex 屬性,會自動 ImageKey 將 設定為空字串 (「」「) 。

ImageImageAlignImageIndexImageKeyImageScaling 屬性與影像處理的各種層面有關。 直接設定這些屬性,或設定僅限 ImageList 執行時間屬性,以在控制項中使用 ToolStrip 影像。

影像縮放是由 和 ToolStripItem 中的 ToolStrip 屬性互動所決定,如下所示:

ImageList如果屬性值變更為 null ,則 ImageIndex 屬性會傳回其預設值 -1。 不過,指派 ImageIndex 的值會在內部保留,並在將另一個 ImageList 物件指派給 ImageList 屬性時使用。 如果指派給 ImageList 屬性的新 ImageList 具有 ImageList.ImageCollection.Count 小於或等於指派給 ImageIndex 屬性的值減一 (,以將集合視為以零起始的索引) ImageIndex ,屬性值會調整為小於 Count 屬性值的一個。 例如,假設按鈕控制項有 ImageList 三個影像,且其 ImageIndex 屬性設定為 2。 如果只有兩個影像的新 ImageList 指派給按鈕,此值 ImageIndex 會變更為 1。

適用於