Share via


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

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

在清單檢視中顯示影像

  1. 將適當的屬性 SmallImageList 、、 LargeImageListStateImageList 設定為您想要使用的現有 ImageList 元件。

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

    listView1.SmallImageList = imageList1;
    
    
    ListView1.SmallImageList = ImageList1
    
    
  2. ImageIndex設定具有相關聯圖示之每個清單專案的 或 StateImageIndex 屬性。

    這些屬性可以在程式碼中設定,或在 ListViewItem 集合編輯器 設定。 若要開啟 ListViewItem 集合編輯器 ,請按一下 [屬性 ] 視窗上 屬性旁邊的 Items 省略號按鈕 ( The Ellipsis button (...) in the Properties window of 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
    
    

另請參閱