共用方式為


HOW TO:顯示 Windows Form ListView 控制項的圖示

更新:2007 年 11 月

Windows Form ListView 控制項可以顯示來自三個影像清單的圖示。List、Details 以及 SmallIcon 檢視會根據 SmallImageList 屬性中指定的影像清單來顯示影像。LargeIcon 檢視根據 LargeImageList 屬性中指定的影像清單來顯示影像。清單檢視還可以顯示額外的圖示集,這些圖示在 StateImageList 屬性中設定,顯示在大圖示或小圖示的旁邊。如需影像清單的詳細資訊,請參閱 ImageList 元件 (Windows Form)HOW TO:使用 Windows Form ImageList 元件加入或移除影像

如果要在清單檢視顯示影像

  1. 將適當的屬性 (SmallImageListLargeImageListStateImageList) 設定為要使用的現有 ImageList 元件。

    您可以使用 [屬性] 視窗或程式碼在設計工具中設定這些屬性。

    ListView1.SmallImageList = ImageList1
    
    
    listView1.SmallImageList = imageList1;
    
    
    listView1.set_SmallImageList(imageList1);
    
    
  2. 設定有相關圖示的各個清單項目的 ImageIndexStateImageIndex 屬性。

    您可以在程式碼或 [ListViewItem 集合編輯器] 中設定這些屬性。若要開啟 [ListViewItem 集合編輯器],請按一下 [屬性] 視窗中 Items 屬性旁邊的省略按鈕 (VisualStudioEllipsesButton 螢幕擷取畫面)。

    ' Sets the first list item to display the 4th image.
    ListView1.Items(0).ImageIndex = 3
    
    
    // Sets the first list item to display the 4th image.
    listView1.Items[0].ImageIndex = 3;
    
    
    // Sets the first list item to display the 4th image.
    listView1.get_Items().get_Item(0).set_ImageIndex(3);
    
    

請參閱

工作

HOW TO:使用 Windows Form ListView 控制項加入和移除項目

HOW TO:將資料行加入至 Windows Form ListView 控制項

HOW TO:將自訂資訊加入 TreeView 或 ListView 控制項 (Windows Form)

參考

ListView 控制項概觀 (Windows Form)

其他資源

ImageList 元件 (Windows Form)