ListViewItem.ImageIndex 屬性

定義

取得或設定為項目顯示的影像索引。

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.NoneExcludedImageIndexConverter))]
public int ImageIndex { get; set; }
[<System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.ImageIndexConverter))>]
member this.ImageIndex : int with get, set
[<System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.NoneExcludedImageIndexConverter))>]
member this.ImageIndex : int with get, set
Public Property ImageIndex As Integer

屬性值

ImageList 中為項目顯示之影像的以零起始的索引。 預設值為 -1。

屬性

例外狀況

value 小於 -1。

備註

此屬性的值取決於 屬性的值 ImageList 。 根據與專案相關聯之控制項的目前屬性值 View ,專案所使用的 可以是 屬性或 SmallImageList 控制項的 ListView 屬性中指定的 LargeImageListImageListListView View如果屬性設定為 LargeIcon ,則會 ImageList 使用 屬性中指定的 LargeImageListImageList 否則會使用 屬性中指定的 SmallImageList 。 在 屬性中指定的 中 ImageListSmallImageList 定義的影像應該具有相同索引位置,與 屬性中指定的 LargeImageList 影像 ImageList 相同。 如果這兩 ImageList 個控制項的索引位置都相同,您可以設定屬性的單一索引值 ImageIndex ,而不論 View 控制項的 ListView 屬性值為何,都會顯示適當的影像。

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

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

適用於

另請參閱