Windows 窗体 ListView 控件可以显示三个图像列表中的图标。 “列表”、“详细信息”和“SmallIcon”视图显示 SmallImageList 属性中指定的图像列表中的图像。 LargeIcon 视图显示 LargeImageList 属性中指定的图像列表中的图像。 列表视图还可以显示一组附加的图标,在 StateImageList 属性中设置,位于大图标或小图标旁边。 有关图像列表的详细信息,请参阅 ImageList 组件 和 如何:使用 Windows 窗体 ImageList 组件添加或删除图像。
在列表视图中显示图像
将相应的属性(SmallImageList、LargeImageList或 StateImageList)设置为要使用的现有 ImageList 组件。
可以使用“属性”窗口或代码在设计器中设置这些属性。
listView1.SmallImageList = imageList1;
ListView1.SmallImageList = ImageList1
为每个具有关联图标的列表项设置 ImageIndex 或 StateImageIndex 属性。
可以在代码中设置这些属性,也可以在 ListViewItem Collection Editor中进行设置。 若要打开 ListViewItem 集合编辑器,请单击属性窗口中 Items 属性旁边的省略号按钮 (
)。
// 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