如何将图像添加到 ListViewItem 或 ListView c# [英] How to add an image to ListViewItem or ListView c#

查看:40
本文介绍了如何将图像添加到 ListViewItem 或 ListView c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表视图控件,我正在向该控件添加包含图像数据、文件名、位置(在 4 维矩阵中的某个点处获取)、所用时间的行.为了让事情变得更好,我想在我的第四列中添加一个删除"图标,以便用户可以查看图像并决定是否保留它,如何将图像/图标添加到每行的第 4 个单元格?

I have a listview control, to this control I am adding rows which contain image data, filename, position (its taken at a point in a 4 dimensional matrix), time taken. To make things nice I want to add a 'delete' icon to my fourth column so the user can review the image and decide whether to keep it or not, how do I add an image/icon to that 4th cell in each row?

public void addItemToImageListview(string details, string timestamp)
{
        string reftype = (!exp_image_radiobtn.Checked) ? "Ref" : "Data";
        ListViewItem lvi = new ListViewItem();

        if (details.Contains("[ERROR]"))
        {
            reftype = "[ERROR]";
            details = details.Substring(0, details.IndexOf("[ERROR]"));
        }

        lvi.Text = details;
        lvi.SubItems.Add(reftype);
        lvi.SubItems.Add(timestamp);
        lvi.SubItems.Add(image icon?);

我已经浏览过谷歌,但很多东西都是旧的......

I have looked through Google but a lot of stuff is old...

正如阿伦所问,这是一个 winforms 应用程序,c#,3.5.

As Aren asked, this is a winforms app, c#, 3.5.

推荐答案

不幸的是,在 WinForms 中将列渲染为图像会很痛苦.您必须创建一个所有者绘制的 ListView 并提供绘制该列的逻辑.

Unfortunately, in WinForms rendering a column as an image gets painful. You have to create an owner-drawn ListView and provide the logic for drawing that column.

幸运的是,有开源 ObjectListView 包装器,它使绘制图像在 ListView 子项列中很简单:

Fortunately, there's the open source ObjectListView wrapper, which makes drawing images in ListView subitem columns trivial:

这篇关于如何将图像添加到 ListViewItem 或 ListView c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆