共用方式為


如何:顯示 Windows Form ListView 控制項的圖示

Windows Forms ListView 控制項可顯示來自三份影像清單的圖示。 List、Details 和 SmallIcon 檢視會顯示 SmallImageList 屬性中所指定影像清單中的影像。 LargeIcon 檢視會顯示 LargeImageList 屬性中所指定影像清單中的影像。 清單檢視也可顯示一組額外的圖示,其在 StateImageList 屬性中設定,位於大型或小型圖示旁邊。 如需影像清單的詳細資訊,請參閱 ImageList 元件操作說明:使用 Windows Forms ImageList 元件新增或移除影像

若要在清單檢視中顯示影像

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

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

    listView1.SmallImageList = imageList1;
    
    
    ListView1.SmallImageList = ImageList1
    
    
  2. 針對具有相關聯圖示的每個清單項目,設定 ImageIndexStateImageIndex 屬性。

    這些屬性可以在程式碼中設定,或在 [ListViewItem 集合編輯器] 內設定。 若要開啟 [ListViewItem 集合編輯器],請按一下 [屬性] 視窗上 Items 屬性旁的省略符號按鈕 (Visual Studio 的 [屬性] 視窗中的省略符號按鈕 (...)。)。

    // 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
    
    

另請參閱