c# listViewItem.imageindex
时间: 2023-11-18 22:04:52 浏览: 57
在 C# 的 ListView 控件中,ListViewItem 是用于表示列表项的类。imageindex 是 ListViewItem 的一个属性,用于指定该项所对应的图像在 ImageList 控件中的索引。如果我们想要在 ListView 中显示图像,我们需要使用 ImageList 控件来管理图像,并将其与 ListView 控件关联。例如,假设我们有一个包含两个图像的 ImageList:
```
ImageList imageList = new ImageList();
imageList.Images.Add(Image.FromFile("image1.png"));
imageList.Images.Add(Image.FromFile("image2.png"));
```
然后我们可以创建两个 ListViewItem,并分别将它们与 ImageList 中的图像关联:
```
ListViewItem item1 = new ListViewItem("Item 1", 0); // 使用索引为 0 的图像
ListViewItem item2 = new ListViewItem("Item 2", 1); // 使用索引为 1 的图像
```
在这里,item1 和 item2 分别使用了 ImageList 中的第一个和第二个图像,因为它们的 imageindex 属性分别设置为 0 和 1。最后,我们将这些 ListViewItem 添加到 ListView 控件中:
```
listView1.Items.Add(item1);
listView1.Items.Add(item2);
```
这样,我们就可以在 ListView 中显示图像了。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)